forked from NohaAShehab/Devops43R1Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringss.py
More file actions
116 lines (105 loc) · 3.46 KB
/
stringss.py
File metadata and controls
116 lines (105 loc) · 3.46 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""<---- strings - -> sequence of chars ---> """
# name = 'Ahmed Ali Mohamed'
# "1- get no of char in string "
# print(len(name))
#
# """ string is treated like an array --> access string parts using index start from 0"""
# print(name[1])
# print(name[1:4])
# print(name[:10])
# print(name[::-1]) # reversed
#
# """ string is immutable ---> once created cannot be changed"""
# # print(name[10])
# # name[10]='@'
#
# """ count no of char in the string """
# print(name.count('a'))
# print(name.count('md'))
#
# """get index of char ? """
# message = 'iti'
# print(message.index('i')) # return with the first occurrence of the char in the string
#
# """ operations on the strings ====> return new string """
#
# """ string formatting """
# template = "My name is {0} I works at {1}"
# print(template.format('Noha', 'ITI'))
# print(template.format('ITI', 'Noha'))
# "--- template ---> keyword"
# template = "My name is {name} I works at {work}"
# print(template)
# print(template.format(work='iti',name='noha'))
#
# """replace string --> part of string """
# message = 'I love iti o o o '
# print(message.replace('o', '@'))
# print(message.replace('o', '@', 2))
#
#
# """ format string ---> f-format string --> format string according to existing variables """
# name = 'Ahmed'
# work = 'Microsoft'
# year = 32234
# temp = f"My name is {name}, I works at {work} {year}"
# print(temp)
# """ string concatenation, string interpolation """
# fname = 'Noha'
# midname = 'Abdelhady'
# lname = 'Shehab'
# test = 10
# '+ ---> valid only between values from the same type '
# # fullname = fname + midname + midname + lname
# # fullname = fname + midname + midname + lname + test # TypeError: can only concatenate str (not "int") to str
#
# fullname = fname + midname *2 + lname # string intepolation ---> multiply string by int
# print(fullname)
# print('test'*44)
# """ ask user to enter data to the application """
#
# message = input("please enter message ") # always returns with string
# print(message, type(message))
#
# """ format operations on the string """
# print(message.upper())
# print(message.lower())
# print(message.capitalize())
# print(message.title()) # capitalize first char in each word
# """ examine string content ?"""
# # print(message.isupper())
# # print(message.islower())
# # print(message.isalpha()) # return True ---> if the string consists only from alphas from a -> Z
# print(message.isdigit()) # return True ---> if the string consists only from digits from 0--> 9
#
# # age = input("please enter age : ")
# # if age.isdigit():
# # age = int(age)
# # print(age*10)
#
# deduction = input("please enter deduction percentage ")
# # d = int(deduction) # -10
# # if deduction.isdigit(): # deosn't feel negative numbers --> 0--->9
# # deduction = int(deduction)
#
# # if deduction.isnumeric(): # 5 --->
# # deduction = int(deduction)
# #
# message= input("please enter message : ")
# print(message.isspace())
""" ====> operations on string ---> strip string """
message = ' Nice to meet you '
yourmessage = input("please enter message ")
print(message)
print(yourmessage)
print(yourmessage.strip()) # remove spaces from the beginning and the end of the string
print(f"{yourmessage.lstrip()}#")
print(f"{yourmessage.rstrip()}#")
""" strip pattern of chars """
print(f"#{yourmessage.strip('A i$')}#") # remove char from the beginning and the end of the string
num = 4+5j
print(num, type(num))
numm =complex(3,45)
""" check existence """
if 'a' in 'noha':
print('hi')