DEV Community

ABYS
ABYS

Posted on • Updated on

My First Blog _Python

Hi All,

This is my very first blog. I'm a Biomath student who has zero knowledge about computer related stuffs.
Later, I was convinced to study a programming language yet confused with how,where and what to start...?

And finally decided to learn python, as people around me implied that it's easy to start with... So, now I'm learning python from an online platform., which teaches me so fine...

I thought of blogging it all, cause people like me will get to know that python isn't overly challenging rather as simple as English grammar.

We can learn python just by using "Google Colaboratory", yet I would let u know how to install python later.

So, join with me...
Let's start to learn PYTHON


PYTHON BASICS

1. Printing a String :

  • To print a text, we use print function - print()

  • Let's begin with "Hello World".

  • By writing certain text within the print function inside double or single quotes, we get :

print("Hello World")

Hello World

Enter fullscreen mode Exit fullscreen mode

2. Similarly, we can Print Variables :

  • Variables are used to store data.
name = "Abys"
print(name)

Abys

Enter fullscreen mode Exit fullscreen mode
  • Here, if we give numbers as values for the variable (ex: age=25) we needn't provide them under double or single quotes as they give the same output but as for texts we should use "" or ''.
age = 25 
print(age)

25

age = "25"
print(age)

25

name = Abys
print(name)

Traceback (most recent call last):
  File "./prog.py", line 4, in <module>
NameError: name 'Abys' is not defined

Enter fullscreen mode Exit fullscreen mode
  • That's the reason for this rule. Hope it's clear.,

3. Printing Multiple Items :

  • We can print multiple items by separating them with commas while python adds space between each item.

  • Formatting strings with f strings is another sub topic where we insert variables directly into the string by prefixing it with an f and using curly braces {} around the variables.

let's see both,

name="Abys"
age=17
city="Madurai"
print("Name:",name , "Age:",age , "City:",city ,end=".")

Name: Abys Age: 17 City: Madurai.


name="Abys"
age=17
city="Madurai"
print(f"Name:{name},Age:{age},City:{city}.")

Name:Abys,Age:17,City:Madurai.

Enter fullscreen mode Exit fullscreen mode

4.Concatenation of Strings :

  • Here, we connect words using + operator.
w1="Sambar"
w2="Vada"
print(w1+" "+w2+"!")

Sambar Vada!

Enter fullscreen mode Exit fullscreen mode
  • Let's also see what is Printing Quotes inside Strings.

  • To print quotes inside a string, we can use either single or double quotes to enclose the string and the other type of quotes inside it.

w1="Sambar"
w2="Vada"
print("I love" , w1+" "+w2+"!")

I love Sambar Vada!

hobby = "Singing"
print("My hobby is" , hobby)

My hobby is Singing

Enter fullscreen mode Exit fullscreen mode

5.Escape Sequences and Raw Strings to Ignore Escape Sequences :

  • Escape sequences allows to include special characters in a string. For example, \n adds a new line.
print("line1\nline2\nline3")

line1
line2
line3

Enter fullscreen mode Exit fullscreen mode
  • r string is used as prefix which treats backslashes as literal characters.
print(r"C:\Users\Name")

C:\Users\Name

Enter fullscreen mode Exit fullscreen mode

6.Printing Results of Mathematical Expressions :

  • We've already seen how to print numbers.
print(26)

26

Enter fullscreen mode Exit fullscreen mode
  • Now, we're going to print certain eqns.
print(5+5)

10

print(3-1)

2

Enter fullscreen mode Exit fullscreen mode

that's how simple it is...

7.Printing Lists and Dictionaries :

  • We can print entire lists and dictionaries.
fruits = ["apple", "banana", "cherry"]
print(fruits)

['apple', 'banana', 'cherry']

Enter fullscreen mode Exit fullscreen mode

8.Using sep and end Parameters :

  • The sep parameter changes the separator between items.

  • The end parameter changes the ending character.

print("Happy", "Holiday's", sep="-", end="!")

Happy-Holiday's!

Enter fullscreen mode Exit fullscreen mode
  • Let's see how to print the same in adjacent lines, here we use either escape sequences (\n) or Multiline Strings.

  • Triple quotes allow you to print multiline strings easily.

print("""Happy
Holiday's""")

print("Happy\nHoliday's")

Enter fullscreen mode Exit fullscreen mode

both gives same output as :

Happy
Holiday's

Enter fullscreen mode Exit fullscreen mode

9.Combining Strings and Variables :

  • Combining strings and variables by using + for simple cases or formatted strings for more complex scenarios.

  • For simple case:

colour = "purple"
print("The colour of the bag is "+colour)

The colour of the bag is purple

Enter fullscreen mode Exit fullscreen mode
  • For complex case :
temperature=22.5
print("The temperature is", str(temperature),"degree Celsius",end=".")

The temperature is 22.5 degree Celsius.

Enter fullscreen mode Exit fullscreen mode

10.Printing with .format() and Using print for Debugging:

  • Use the .format() method for string formatting.
name="Abys"
age=17
city="Madurai"
print("Name:{}, Age:{}, City:{}".format(name,age,city))

Name:Abys, Age:17, City:Madurai

Enter fullscreen mode Exit fullscreen mode
  • We can use print to debug your code by printing variable values at different points.
def add(a, b):
    print(f"Adding {a} and {b}")
    return a + b

result = add(1, 2)
print("Result:", result)

Adding 1 and 2
Result: 3

Enter fullscreen mode Exit fullscreen mode

That's it.
These were the topics I learned in my 1st class.

At the beginning, I was confused by all the terms but as time went I got used to it just like we first started to learn English.

Try it out yourself... as u begin to get the output., it's next level feeling.
I personally felt this;
"Nammalum Oru Aal Than Pola"...

.....

Top comments (2)

Collapse
 
muadiv profile image
Muadiv

Hey, nice that you started this path !! A small detail ...

print("Hello World")

HelloWorld
Enter fullscreen mode Exit fullscreen mode

Should be:

print("Hello World")

Hello World
Enter fullscreen mode Exit fullscreen mode

:)

Collapse
 
abys_learning_2024 profile image
ABYS

Noted