-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString&TypesConversions.py
More file actions
132 lines (94 loc) · 2.73 KB
/
Copy pathString&TypesConversions.py
File metadata and controls
132 lines (94 loc) · 2.73 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
""""
Unicode is a universal character encoding standard that
assigns a unique number (code point) to every character,
regardless of language
we can check them by using ord() function in python and
convert them back using chr() function.
"""
a="A"
print(ord(a))
b=65
print(chr(b))
# String Indexing
"""
Indexing starts from 0 and
goes till the number of characters you have.
There is negative indexing as well and it starts from -1, but
the starting position is from the back of the strin
"""
c="Himanshu"
print(c[0])
print(c[1])
print(c[2])
print(c[3])
print(c[-1])
# String Slicing
"""" Slicing means cutting out a slice from string and this is also
done using index values
eg - a = “hello” a[1:4:1] ==> output “ell
So here we have start , stop and steps position and keep a
note if we use stop at 4 it will slice till 3 only.
"""
d="Gym Boy Himanshu"
#how to slice
# D[start : stop : step positions]
print(d[0:3:1])
print(d[4:8:1])
# Types Conversion
""" For understanding type conversion you have to look at these 4 things
1) int()
2) float()
3) str()
4) bool()
There are more functions like this but these are 4 main
function, looking at these functions you can guess these are
used to convert one data type to another
"""
#example
e=12
f=0
print(bool(e))
print(bool(f))
print(str(e))
print(complex(e))
print(float(e))
# Note
""" There are truthy values and Falsy values, and there are only
7 falsy values that means only 7 things will be converted to
false rest True.
1) 0
2) 0.0
3) False
4) ""
5) []
6) {}
7) ()
All these values are falsy remaining will be converted to True.
"""
# Types of Conversions
"""
There are 2 Types Of Conversions Implicit and Expilicit.
Implicit:
In this python automatically
converts data from one data
type to another.
You have already seen the
example before
e.g-> a=12
print (a/2)
output - 6.0
Explicit:
--------->
In this we as a user use in build
functions to convert one data
type to another
int()
float()
complex()
str()
list()
tuple()
set()
dict()
bool()
"""