-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumbers and Variables.py
More file actions
48 lines (37 loc) · 1.3 KB
/
Numbers and Variables.py
File metadata and controls
48 lines (37 loc) · 1.3 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
"""
There are certain rules for Naming Variables in python to use variables effectively.
Variable names can only contain letters, digits and underscores (_)
A variable name cannot start with a digit
Variable names are case-sensitive
Avoid using Python keywords like if, else, for as variable names
Python variables do not require explicit declaration of type
"""
x = 10
name = "My Name"
print(x)
print(name)
#Multiple assignment - same value can be assigned to multiple variables
a = b = c = 100
print("Values of a, b and c :",a, b, c)
#Assign different values - Different value to multiple variables
x, y, z = 1, 2.5, "Satya"
print("Values of x, y and z :",x, y, z)
# Swap variables
a, b = 5, 10
a, b = b, a
print("Values of a and b after swapping a with b:", a, b)
# Counting Length of a word in python. It counts space as a character
word = "TestPython"
word2 = "Test Python"
length = len(word), len(word2)
print("Length of 'TestPython' and 'Test Python' are :", length)
#Write a program which will find factors of given number and find whether the factor is even or odd.
number = 69
print("The factors of {} are,".format(number))
for i in range(1,number+1):
if number % i == 0:
print(i)
if i%2==0:
print(i, "It is an Even Number")
else:
print(i, "It is an Odd Number")