-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.py
64 lines (46 loc) · 1.29 KB
/
variables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#assigning variable is ease in python
#if we put some sort of value in any alphabet or word, without any indication it works as variable
#eg
x = "Nepal"
Favourite_Hero = "Iron Man"
print(x)
print(Favourite_Hero)
#naming rule
#legal variables name
myvar = 1
my_var = 2
_myvar = 3
MYVAR = 4
MyVar1 = 5
#illegal variables name
# 2myvar = "a" my-var = "b" my var = "c"
#single value to multiple variable and multiple variable
x,y,z = 10,20,30
m =n =o ="Java"
# print() statement prints the value stored in variable
print(m)
print(o)
print(n)
# + character is used to conccate variables
a = "Ram"
b = " and "
c = "Shyam"
print(a+b+c)
#global variable and local variable
#variable in global scope is global variable i.e not inside any function
#variable inside a function is local variable and can ve used in that funcction only
name = "harry"
def function():
name1 = "garry"
print (name1)
print(name)
#inside this function both name and name1 are printed
print(name)
#print(name1)
#name1 cant be printed as it is not global variable
#variable inside function can be made global variable using global keyword but function should be called before that.
def function2():
global name2
name2 = "marry"
function2()
print(name2)