Day 2 of learning python

mastering python fundamentals in 10 days

Aviral Bhardwaj
4 min readApr 19, 2022

hey guys it’s your second day of learning python

in this article, we would be covering these topics

  • datatypes and their uses
  • conditional statements
  • operators in python

Datatypes

datatypes are very important in any programing language we have the following datatypes

Text

string

string is a text representation in python and anything inside “ ”

Numeric

we have 2 types of datatypes in Numeric one is integer and the other is float

integer

integer is a numeric representation of an integer (1,10,135)

Float

Float is also a numeric representation but it’s different it includes real numbers or in simple language, if the number has a decimal point it is considered as a float (54.6,62.379,10.0)

you will also learn about sequence data types (list, dictionary, and tuples) on day 4

so in the code, we are assigning a value to a,b,c well this is a variable we will talk about this in our future article

as you can see that if we want to know the type of a variable we can know by it the following command

output

as a is an integer so it’s returning its class and similarly with others

there’s a good question as you guys know that 10.0=10 but the class is different because of the involvement of decimal points so 10.0 is considered as a float, not an integer

Conditional statements

conditional statements to perform a particular task if any condition goes true there are 3 conditional statements if, else,elif

if

it has a code of body that runs only if the condition of the if command come to true

else

else runs a body command if the condition is not satisfied by if and elif

Elif

The Elif keyword is used in conditional statements (if statements), and is short for else if. similar to if the command

here we are making a simple program to explain to you guys how does if-else elif works

so we are taking two numbers 20 and 10 and we are assigning its value to a and b now as I have told you what does if-else elif does you can change the numbers and try more examples on it

so I am defining a simple condition
if a is bigger than b then it will run the body of command present in the if
similarly is for elif if our condition does not satisfied by if so it will check that if the condition is true in elif if it’s true then it will the code within

else is different if the condition is not satisfied by if and elif or the condition comes out of range then it will run the body of command present in

operators

operators are used to perform operations on variables and value

Arithmetic operators

it can do basic operations on numbers and in some cases, it can work on strings
addition, subtraction, multiplication, division, and many more operations
so let’s take an example of a and b and we are assigning the values of a and b
so we are adding two numbers a and b and we can do many operations on them just like this

Bonus tip — we can add two strings like this

Comparison operators

used to compare two variables or values

there are some more operators

  • Logical operators
  • Assignment operators
  • Identity operators
  • Membership operators
  • Bitwise operators

conclusion

I hope you all had a good understanding of today’s topics. On day 3, we will cover the variable, comments, escape characters, input function, and typecasting.

--

--

Aviral Bhardwaj

One of the youngest writer and mentor on AI-ML & Technology.