Tuesday, September 17, 2019

Variables in Python

            Python is a complete object oriented. every variable in python is a an object. A variable is the name used to access a value. A variable is named location which is used to store data in the memory which can be replaceable.
           Every variable have a unique name called identifier. identifier helps to variables as container to hold data which can be changed later at any time of the programming.
Ex.
>>> python=45
>>> print(python)
45
>>> 
This code creates a variable called python, and assigns to it, integer number as 45. when we ask python to tell us what is stored in the variable python, it returns that number again.

Declaring Variables in python:
   Variables in python do not need any declaration to reserve memory space. The variable declaration happens automatically when we assign a value to a variable.

There are some rules with variable name in python:
=>  it can only be an only word.
=>  it can only use letters, numbers and underscores(_).
=>  Hyphens are not allowed (-).
=>  Spaces are not allowed.
=>  it cant't begin with a number.
=>  Special characters are not allowed such as $ or '.

points to remember:
 =>  variable names are case sensitive, NAME and name are different variables.
=>  it is convention in python to use all lower case letters for variable name, using underscore(_)             separators.
=>  a good variable name describes the data it contains.

declaring and assigning a value to a variable:
Syntax:
           VariableName= "Assigning Value"
Example:
>>> blog="blogger.com"
>>> print(blog)
blogger.com
>>> 

changing value of a variable:
Syntax:
           VariableName= "new assigning value"
Example:
>>> blog="codingpartnerr"
>>> print(blog)
codingpartnerr
>>> 

Assigning multiple value to a multiple variables:
Syntax:
            Variable1, Variable2, Variable3=  "Value1","Value2","Value3"
Example:
>>> a,b,c= 45,18, 'hello'
>>> print(a)
45
>>> print(b)
18
>>> print(c)
hello
>>> 


If You like this content, so please go for a comment and give your feedback.


INSTAGRAM

No comments:

Post a Comment

type keyword in python

  Python have a built-in method called as a type. If  a single argument (object)  is passed to type() built-in , it returns the type of obj...