DEV Community

Cover image for L2 VARIABLES AND DATATYPES
Logical-Developer-Gaurav
Logical-Developer-Gaurav

Posted on

L2 VARIABLES AND DATATYPES

WAYS TO USE SINGLE QUOTES , DOUBLE QUOTES AND TRIPLE QUOTES IN A STRING

LAST.png

NOTE -

  • Multi - line string can only be stored in triple quotes.

  • If you want some inverted commas to be the part of your string then you can use triple quotes.

L-2 , 50:00

METHOD TO IDENTIFY THE DATATYPE OF VARIABLE

  • use type function

1.png
NOTE -
From datatype of variable 'd' you can clearly figure out that if you store any datatype inside quotes in any variable then that datatype will be considered as string only

OPERATORS IN PYTHON

ARITHMETIC OPERATORS - These are used to perform arithmetic operations on variables
ARITHMETIC OPERATORS ARE +,-,/,* etc

2.png
NOTE -
From the above example we can see that whenever we perform division operation on 2 numbers in python then it returns the answer in float datatype

And dont forget to use the higlighted comma in between otherwise it will show error

ASSIGNMENT OPERATORS - These are used to assign a value to the variable
ASSIGNMENT OPERATORS ARE =,+=,-=,/=,*= etc

3.png

*COMPARISON OPERATOR * - These are used to compare two expressions and tell whether it is true or false .
COMPARISON OPERATORS ARE ==,>,>=,<,<=,!=

1.png

*LOGICAL OPERATOR * - Logical operators in python are used on conditional statements i.e. on true and false
Logical operators are and , or , not

  • and returns true if both the values are true
  • or returns true if any one of the values is true
  • not makes true , false and false , true

2.png

TYPE FUNCTION AND TYPECASTING

3.png

*TYPE CASTING INT TO FLOAT AND STRING*

4.png

TYPECASTING FLOAT TO INT AND STRING

5.png

TYPECASTING STR TO INT AND FLOAT

6.png

NOTE - **
**If the string contains decimal point then you cannot directly typecaste it into integer datatype , you first need to convert it into float and then to integer

7.png

INPUT FUNCTION

It allows the coder to take input from the users as a string

SYNTAX: a=input('enter something')

Top comments (0)