-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_code.py
More file actions
56 lines (42 loc) · 1.2 KB
/
python_code.py
File metadata and controls
56 lines (42 loc) · 1.2 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
#print command:
print('Hello World')
a = 10
print(a)
# print array:
c = [1, 2, 3, 4, 5]
print(c)
#print type command:
print(type(10))
# print range command: range(start, stop, step)
# start: optional, at 0 for default; stop: mandatory; step: optional, 1 by default
for i in range(10):
print(i)
print(round(23.5678,2))
#input commands
x = input("Enter value: ")
print(x)
print(type(x))
stringword = input("Enter sentence: ")
print(stringword)
print(len(stringword))
# round command
print(round(23.5678,2))
#loop commands:
y = 1
while y < 10:
print(y)
y = y + 1
names = ["A", "B", "C", "D"]
for z in names:
print(z)
#string commands:
str = "123%Hello"
print(str.isalnum()) #isalnum command checks whether given string is in alphanumeric order or not
str1 = "hello"
print(str1.capitalize()) #capitalize command capitalizes given string
print(str1.find("h")) #string.find(substring); string: string in which you want to search; substring: value that you want to search
print(str1.count("l", 1, 5)) #count function returns the count of occurences of a substring in a string object
#syntax: stringname.count(substring, start, end)
str2 = "InterviewBit"
newstr = str2.center(18, "*")
print(newstr)