-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPython Strings.py
More file actions
47 lines (46 loc) · 1.2 KB
/
Python Strings.py
File metadata and controls
47 lines (46 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
# Python Strings
# Strings declarations
name = "saddam arbaa"
job = "Web Programmer"
# Multiline Strings
message = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
# print
print("Name:", name)
print("Job:", job)
print("message:", message)
# String Concatenation
firstName = input("Enter Your first name: ")
lastName = input("Enter Your last name: ")
# Concatenation
fullName = firstName + " " + lastName
print("Yor Full Name is ",fullName)
# for test only
test = 'Concatenation'
# output "Concat"
print(test[0] + test[1] + test[2] + test[3] + test[4] + test[5])
# output "ion" Backward Indexing
print(test[-3] + test[-2] + test[-1])
# print characters from position 3 to position 6
print(test[3 : 6])
# print characters from position 6 to position 3 (Negative Indexing)
print(test[-6 : -3])
# String Length
print(len(test))
# lower()
print(test.lower())
# upper()
print(test.upper())
# replace() method replaces a string with another string :
print(test.replace("a", "?"))
# print from index 3 to last index
print(test[3:])
# Check String
print("ion" in test)
# String Format
name = "saddam arbaa {} {}"
age = 30
id = 212
print(name.format(age, id))