-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.py
More file actions
95 lines (77 loc) · 2.35 KB
/
string.py
File metadata and controls
95 lines (77 loc) · 2.35 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
89
90
91
92
93
94
95
# Multiline String
# a = """WhatsApp is often contested as the world’s most popular
# messaging app, allowing its users to communicate securely and
# in real-time. As a business owner, you can build upon the speed
# and security provided by WhatsApp to engage with your customers,
# send alerts and notifications, provide customer support,
# or even send One-Time Passwords (OTPs) to your customers.."""
# print(a[:8])
#
# a = '''Lorem ipsum dolor sit amet,
# consectetur adipiscing elit,
# sed do eiusmod tempor incididunt
# ut labore et dolore magna aliqua.'''
# print(a)
#Slicing
# b = "Hello, World!"
# print(b[-5:-2])
a = " HELOO SEMUANYA "
print(a.upper())
print(a.lower())
print(a.capitalize())
print(a.strip())
b = "Mr."
c = "Jhon Doe"
print(b + " " + c)
# String repetition
# repeat_string = "Python! " * 3
# print(repeat_string)
# Accessing string characters
# sample_string = "Hello World"
# first_letter = sample_string[0]
# print("First letter:", first_letter)
# last_letter = sample_string[-1]
# print("Last letter:", last_letter)
# String length
# string_length = len(sample_string)
# print("Length of string:", string_length)
# String methods
# lowercase_string = sample_string.lower()
# print("Lowercase:", lowercase_string)
# uppercase_string = sample_string.upper()
# print("Uppercase:", uppercase_string)
# String formatting
age = 30
name = "Budiawan"
info = "My name is {} and I am {} years old.".format(name, age)
print(info)
# f-string (available from Python 3.6+)
info_fstring = f"My name is {name} and I am {age} years old."
print(info_fstring)
nama = "Mahendar"
umur = 35
nidn = 1331108701
tinggal = "Lambaro, Aceh Besar"
tempatLahir = "Lhokseumawe"
tglLahir = "33 november 1988"
sertifikat = f"""
Sertifikat Pelatihan Pemrograman Python :
=========================================
Nama \t \t \t: {nama}
umur\t \t \t: {umur}
nomor Induk \t \t : {nidn}
Alamat \t: {tinggal}
tempat/tglLahir \t: {tempatLahir} / {tglLahir}
ini merupakan sertifikat "otentik"
"""
print(sertifikat)
z = "INi adalah ijazah otentik \"Otentik\". \nJadi adalahaaaa adalah jangan disalahgunakan! / diganti"
print(z.count("adalah"))
repeat_string = "Python! " * 10
print(repeat_string)
# Accessing string characters
sample_string = "Hello World"
first_letter = sample_string[0]
print("First letter:", first_letter)
last_letter = sample_string[-1]
print("Last letter:", last_letter)