Learn Python for the Absolute Beginner (2021 Grasp Basic Python Online with Role Model)

Learn Python for the Absolute Beginner (2021 Grasp Basic Python Online with Role Model)


Learn python for absolute beginners, Learn python online




What are the variables in python?

The variables can be simply defined as the data types which store the values in it 


-> Variables plays a key role in the python programming language 

 
Creating a Variable :

-> There is no command in python for creating a variable 

-> we just have to assign a certain value to a datatype then the data type will be called as the variable 

->  we can change the name of the variable at any time the name of the variable was domestic 

-> In python, we can declare the variables at anywhere and at any time we just have to assign a value to it 

Example for creating a variable :

x = "25" #here x is said to be the variable that stores value 25 in it 
print (x)

output: 25 


How to set the Variable Name: 

A variable that was created for any purpose must have a name and the name must have to be beyond the rules 

->  A variable name must be short and perfect 

->  Variable name must have to start with a letter or underscore 

->  Variable name cannot start with a number 

->  Variable name can only contain the alphanumeric values like ( A- z ,0-9) 

-> Variable names can be written without the spaces 


Example: 

myvar = "ram" 
my_var = "ram"
_my_var = "ram" 
MY VAR  = "ram" 

output: ram 
            ram 
            ram 
            ram 


Assigning one value to multiple variables:

We can assign the multiple values to the multiple variables

Example: 

x = y = z = 525

print(x)
print(y)
print(z)

output:  x = 525
             y = 525
             z = 525


Assigning multiple values to multiple variables: 

we can assign the  multiple values to multiple variables in python 

x,y,z = ( '525', '548', '334')
print(x)
print(y)
print(z) 

output:  x = 525
             y = 548
             z = 334


Unpack a collection: 

if you have a collection of values python allows extracting the values into the variables 


Example: 

Numbers = ['525'. '225', '335']
x,y,z = Numbers
print(x)
print(y)
pritn(z) 

Post a Comment

Previous Post Next Post