Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8974b79

Browse files
small changes
1 parent 949ef25 commit 8974b79

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

‎Python Basics/variables.py

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /