-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02.py
More file actions
88 lines (73 loc) · 2.63 KB
/
02.py
File metadata and controls
88 lines (73 loc) · 2.63 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
# Integer Input and Operations
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
sum_result = num1 + num2
print("Sum of two numbers is", sum_result)
print(type(sum_result))
diff = num1 - num2
print("Difference of two numbers is", diff)
print(type(diff))
product = num1 * num2
print("Product of two numbers is", product)
print(type(product))
quotient = num1 / num2
print("Quotient of two numbers is", quotient)
print(type(quotient))
remainder = num1 % num2
print("Remainder of two numbers is", remainder)
print(type(remainder))
# Boolean Input and Operations
bool1 = bool(int(input("Enter first boolean (0 for False, 1 for True): ")))
bool2 = bool(int(input("Enter second boolean (0 for False, 1 for True): ")))
print("Boolean AND operation:", bool1 and bool2)
print("Boolean OR operation:", bool1 or bool2)
print("Boolean NOT operation on first boolean:", not bool1)
print("Type of boolean result:", type(bool1 and bool2))
# String Input and Operations
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
concat = str1 + str2
print("Concatenation of strings:", concat)
print("Type of concatenation result:", type(concat))
repeat3 = str1 * 3
print("Repeating first string 3 times:", repeat3)
print("Type of repeated string:", type(repeat3))
#comparison operators
print(num1>=num2)
print(num1<=num2)
print(num1==num2)
print(num1!=num2)
print(num1>num2)
print(num1<num2)
#strings are immutable
#single line string 'or" and multiline string"""
#each character in string is indexed
#also supports negative indexing
strng="hello! world"
strng="hi! there" #reassigning the string
print(strng[0])
print(strng[1])
print(strng[-1])
print(strng[-2])
#slicing is the process of extracting a substring from a string
print(strng[0:4]) #hi! t
print(strng[0:5:2]) #h!t
print(strng[0:5:1]) #hi! t
print(strng[::-1]) #ereht !ih (reversing the string)
print(len(strng)) #length of the string
print(strng[0:len(strng)]) #hi! there
#character is a single symbol in a string
#substring is a sequence of characters in a string
#string methods
#string methods are functions that can be applied to strings to perform various operations
newstr=strng.replace("there", "hi") #replace the substring "there" with "hi"
print(newstr) #hi! hi
print(newstr.lower()) #hi! hi
print(newstr.upper()) #HI! HI
print(newstr.title()) #Hi! Hi
print(newstr.lstrip()) #hi! hi (removes leading and trailing whitespace)
print(newstr.rstrip()) #hi! hi (removes leading and trailing whitespace)
print(newstr.strip()) #hi! hi (removes leading and trailing whitespace)
#9860036647
#isdigit() #checks if the string is a digit
#isupper() #checks if the string is in uppercase