forked from sksalahuddin2828/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy_String.py
77 lines (42 loc) · 1.39 KB
/
Copy_String.py
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
variable_one = "Python"
variable_two = variable_one
print(variable_one, id(variable_one))
print(variable_two, id(variable_two))
# Answer: Python 9723584
# Python 9723584
#----------Explicit String Constructor----------
variable_one = "Python"
variable_two = str(variable_one)
print(variable_one, id(variable_one))
print(variable_two, id(variable_two))
# Answer: Python 9723584
# Python 9723584
#------------------String Slice------------------
variable_one = "Python"
variable_two = variable_one[:]
print(variable_one, id(variable_one))
print(variable_two, id(variable_two))
# Answer: Python 9723584
# Python 9723584
#--------------Add an Empty String--------------
variable_one = "Python"
variable_two = variable_one + ""
print(variable_one, id(variable_one))
print(variable_two, id(variable_two))
# Answer: Python 9723584
# Python 9723584
#----------------Copy Module----------------
import copy
variable_one = "Python"
variable_two = copy.copy(variable_one)
print(variable_one, id(variable_one))
print(variable_two, id(variable_two))
# Answer: Python 9723584
# Python 9723584
#--------------Reverse a String and Reverse back again--------------
variable_one = "Python"
variable_two = variable_one[::-1][::-1]
print(variable_one, id(variable_one))
print(variable_two, id(variable_two))
# Answer: Python 9723584
# Python 9723584