-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatatypes.py
More file actions
60 lines (36 loc) · 1.44 KB
/
Copy pathDatatypes.py
File metadata and controls
60 lines (36 loc) · 1.44 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
#Datatypes in Python
#Numbers
# 2 types of numbers: Integers and Floating-point numbers
int_num = 10 # Integer, can also be negative or zero.
float_num = 10.5 # Floating-point number
#Basic math operations:
# Addition and Subtraction
sum_result = int_num + float_num # 10 + 10.5 = 20.5
diff_result = float_num - int_num # 10.5 - 10 = 0.5
# Multiplication and Division
prod_result = int_num * 2 # 10 * 2 = 20
div_result = float_num / 2 # 10.5 / 2 = 5.25
# Modulus (Remainder)
mod_result = int_num % 3 # 10 % 3 = 1
# Exponentiation / Powers
exp_result = 2 ** 3 # 2 raised to the power of 3 = 8
# Order of Operations follows PEMDAS/BODMAS rules:
complex_calc = (int_num + float_num) * 2 / (3 - 1) # ((10 + 10.5) * 2) / (2) = 20.5
# Strings - Working with text data in Python
# be consistent with single or double quotes
# String Operations
string = "My Name is Preetam Kale." # Double quotes
my_long_string = '''This is a long string that spans multiple lines.
You can use triple single quotes or triple double quotes.''' # Triple quotes for multi-line strings
first_name = 'Preetam' # Single quotes
last_name = "Kale" # Double quotes
full_name = first_name + " " + last_name
long_dash = "-" * 20 # Repeats the dash character 10 times
print(full_name)
print(long_dash)
#length of string
len(long_dash)
len(full_name)
# Accessing characters in a string (indexing starts at 0)
first_char = full_name[0] # 'P'
fifth_char = full_name[4] # 't'