Home > Article > Backend Development > 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.
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") HelloWorld
2. Similarly, we can Print Variables :
name = "Abys" print(name) Abys
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
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. print(f"Name:{name},Age:{age},City:{city}.") Name:Abys,Age:17,City:Madurai.
4.Concatenation of Strings :
w1="Sambar" w2="Vada" print(w1+" "+w2+"!") Sambar Vada!
Let's also see what is Printing Quotes inside Strings.
To print quotes inside a string, you 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
5.Escape Sequences and Raw Strings to Ignore Escape Sequences :
print("line1\nline2\nline3") line1 line2 line3
print(r"C:\Users\Name") C:\Users\Name
6.Printing Results of Mathematical Expressions :
print(26) 26
print(5+5) 10 print(3-1) 2
that's how simple it is...
7.Printing Lists and Dictionaries :
fruits = ["apple", "banana", "cherry"] print(fruits) ['apple', 'banana', 'cherry']
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!
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")
both gives same output as :
Happy Holiday's
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
temperature=22.5 print("The temperature is", str(temperature),"degree Celsius",end=".") The temperature is 22.5 degree Celsius.
10.Printing with .format() and Using print for Debugging:
name="Abys" age=17 city="Madurai" print("Name:{}, Age:{}, City:{}".format(name,age,city)) Name:Abys, Age:17, City:Madurai
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
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 I 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"...
.....
The above is the detailed content of My First Blog _Python. For more information, please follow other related articles on the PHP Chinese website!