-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_Python_Strings.py
More file actions
50 lines (39 loc) · 819 Bytes
/
11_Python_Strings.py
File metadata and controls
50 lines (39 loc) · 819 Bytes
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
# Python Strings
# Strings
print('Hello World!')
print("String 1")
print("")
# Assigning string to a variable
txt2 = "String 2"
print(txt2)
print("")
# Multi-line string
txt3 = """String 3: Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(txt3)
print("")
# Strings are arrays
txt4 = "Learning Python Programming!"
print(txt4[0])
print(txt4[9])
print("")
# Lopping through string
for x in "chess":
print(x)
print("")
# Check string for a word
txt5 = "This products price is free!"
print("free" in txt5)
print("giveaway" not in txt5)
# or
if "free" in txt5:
print("Word found!")
if "giveaway" not in txt5:
print("Word not found.")
print("")
# String length
txt6 = "Lorem ipsum dolor sit amet"
print(len(txt6))
print("")