-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.py
More file actions
156 lines (115 loc) · 1.8 KB
/
Copy pathvariable.py
File metadata and controls
156 lines (115 loc) · 1.8 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Creating Variables
id = 10
name = "Hello"
price = 99.99
is_pass = True
print(id)
print(name)
print(price)
print(is_pass)
# Multiple Variable Assignment
x, y, z = 10, 20, 30
print(x, y, z)
# Same Value to Multiple Variables
a = b = c = 100
print(a, b, c)
# Variable Reassignment
num = 10
print(num)
num = 20
print(num)
# Dynamic Typing
value = 100
print(type(value))
value = "Python"
print(type(value))
value = 10.5
print(type(value))
# Variable Naming Rules
student_name = "John"
studentAge = 20
_marks = 90
salary123 = 50000
print(student_name)
print(studentAge)
print(_marks)
print(salary123)
# Case Sensitive
name = "Alice"
Name = "Bob"
print(name)
print(Name)
# Swapping Variables
a = 10
b = 20
a, b = b, a
print(a, b)
# Delete Variable
x = 100
print(x)
del x
# print(x) # Error
# Check Variable Type
num = 10
text = "Hello"
pi = 3.14
print(type(num))
print(type(text))
print(type(pi))
# Global Variable
x = 100
def show():
print(x)
show()
# Local Variable
def demo():
y = 50
print(y)
demo()
# Global Keyword
x = 10
def change():
global x
x = 50
change()
print(x)
# Variable Unpacking
f_name = ["Rame", "Raje", "Romit"]
a, b, c = f_name
print(a)
print(b)
print(c)
# Print Multiple Variables
name = "Hello"
age = 20
print(name, age)
# Variable Arithmetic
a = 10
b = 5
sum = a + b
sub = a - b
mul = a * b
div = a / b
print(sum)
print(sub)
print(mul)
print(div)
# Variable Concatenation
first = "Hello"
second = "Python"
print(first + " " + second)
# Variable with f-string
name = "Hello"
age = 20
print(f"Name: {name}, Age: {age}")
# --Valid variable names
# name
# student_name
# _age
# marks123
# totalAmount
# --Invalid Variable Names
# 2name # Starts with a digit
# student name # Contains a space
# class # Python keyword
# my-name # Hyphen is not allowed