-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathstrings.py
More file actions
36 lines (30 loc) · 761 Bytes
/
strings.py
File metadata and controls
36 lines (30 loc) · 761 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
# Use single quotes
print("Hello there!")
# Use double quotes
print("Welcome to Real Python!")
# Use triple quotes
print("""Thanks for joining us!""")
# Escape characters
print("I can't believe it!")
print("can't")
# Concatenation
print("Happy" + " " + "pythoning!")
# Built-in functions
print(len("Happy pythoning!"))
# String methods
print(" ".join(["Happy", "pythoning!"]))
print("Happy pythoning!".upper())
print("HAPPY PYTHONING!".lower())
name = "John Doe"
age = 25
print("My name is {0} and I'm {1} years old".format(name, age))
# f-strings
print(f"My name is {name} and I'm {age} years old")
# Indexing
welcome = "Welcome to Real Python!"
print(welcome[0])
print(welcome[11])
print(welcome[-1])
# Slicing
print(welcome[0:7])
print(welcome[11:22])