Follow

Python variable's

Python variable's

Python variable asin value for a objects and researve memory location , python have no command for define variables

Variable's

x=5
y="hallo"
#python understand variable datatype
print(x)
print(y)

Try it Yourself »

Output

5
hallo
who find type of variables
python understand type of variable

Example

x=5
y="hallo world"
#python understand variable datatype
print(type(x))
print(type(y))

Try it Yourself »

Output

Int
string

Variable Names


rules of variable names
  • variable name can't use symbols except underscore(_).
  • variable cannot start with a number
  • variable must start with alphabet or underscore(_).
  • can't use reserve word(keywords)

Example

variable="hallo world"
_myvariable="hallo world"
variable2="hallo world"
Variable="hallo world"

Try it Yourself »
incorrect method of writing a variable

Example

@variable="hallo world"
4myvariable="hallo world"
variable 2="hallo world"
~Variable="hallo world"

Try it Yourself »

addign multipal values


multipal variable have multipal values

Example

x, y, z="hallo","hi","who are you"
print(x)
print(y)
print(z)

Try it Yourself »

Output

hallo
hi
who are you

one value for multiple variables

Example

x, y,z="hallo"
print(x)
print(y)
print(z)

Try it Yourself »

Output

hallo
hallo
hallo

Global Variables

global variable crated outside of function , global variable use inside and outside of function

Global Function

def  myfunc():
    global  x
    x="this is global variable"
myfunc()
print(x)

Try it Yourself »

Output

this is global variable

No comments:

Post a Comment

Tell us how you like it.