|
1 | | -print("Lets learn Data Types with Python") |
2 | | -#------------------------------------------------- |
| 1 | +""" |
3 | 2 | # Data Types with Python |
4 | 3 | #------------------------------------------------- |
5 | | - |
6 | 4 | # Data types in python are a way to classify data items |
7 | 5 | # They represent the kind of value, which determines what operations can be performed on the data |
8 | 6 | # Since everything is an object in python programming |
9 | 7 | # Python data types are classes and variables are instances (objects) of those classes |
10 | | - |
| 8 | +""" |
11 | 9 |
|
12 | 10 | """ |
13 | 11 | The following are standard or built in data types in Python: |
|
35 | 33 | """ |
36 | 34 | ('python', 'for', 'aws') |
37 | 35 | |
38 | | -""" |
39 | | - |
40 | | -# Numeric Data Types |
41 | | - |
| 36 | +Numeric Data Types |
42 | 37 | # python numbers represent data that has a numeric value |
43 | 38 | # A numeric value can be an integer , a floating number or even a complex number |
44 | 39 | # These values are defined as int, float and complex classes |
45 | | -""" |
| 40 | +
|
46 | 41 | Integers: value is represented by int class. It contains positive or negative whole numbers (without fractions or decimals). |
47 | 42 | There is no limit to how long an integer value can be. |
48 | 43 |
|
|
54 | 49 | It is specified as (real part) + (imaginary part)j. |
55 | 50 | For example - 2+3j |
56 | 51 |
|
57 | | -
|
58 | 52 | """ |
59 | 53 | a = 5 |
60 | 54 | print(type(a)) |
|
93 | 87 | s |
94 | 88 |
|
95 | 89 | """ |
96 | | - |
97 | | -#---------------LIST-DATA-TYPE---------------- |
98 | | - |
99 | 90 | """ |
| 91 | +---------------LIST-DATA-TYPE---------------- |
100 | 92 | Lists are similar to arrays found in other languages. |
101 | 93 | They are an ordered and mutable collection of items. |
102 | 94 | It is very flexible as items in a list do not need to be of the same type. |
|
125 | 117 | ['byte', 'gb', 1, 4, 5] |
126 | 118 |
|
127 | 119 | """ |
128 | | - |
129 | | - |
130 | | -#------------- Access List Items----------------- |
131 | 120 | """ |
| 121 | +#------------- Access List Items----------------- |
132 | 122 | In order to access the list items refer to index number. |
133 | 123 | In Python, negative sequence indexes represent positions from end of the array. |
134 | 124 | Negative indexing means beginning from end |
|
154 | 144 | python |
155 | 145 | """ |
156 | 146 |
|
157 | | - |
158 | | -#--------------Tuple Data Type------------------- |
159 | 147 | """ |
| 148 | +--------------Tuple Data Type------------------- |
160 | 149 | Tuple is an ordered collection of Python objects. |
161 | 150 | The only difference between a tuple and a list is that tuples are immutable. |
162 | 151 | Tuples cannot be modified after it is created. |
|
200 | 189 |
|
201 | 190 | """ |
202 | 191 |
|
203 | | -#------------------Boolean Data Type------------- |
204 | | - |
| 192 | +""" |
| 193 | +------------------Boolean Data Type------------- |
205 | 194 | # Python Boolean Data type is one of the two built-in values, True or False. |
206 | 195 | # Boolean objects that are equal to True are truthy (true) and those equal to False are falsy (false). |
207 | 196 | # However non-Boolean objects can be evaluated in a Boolean context as well and determined to be true or false. It is denoted by class |
208 | | - |
| 197 | +""" |
209 | 198 | print(type(True)) |
210 | 199 | print(type(False)) |
211 | 200 |
|
|
215 | 204 | <class 'bool'> |
216 | 205 |
|
217 | 206 | """ |
218 | | -#----------------Truthy and Falsy Values-------- |
219 | | - |
| 207 | +""" |
| 208 | +----------------Truthy and Falsy Values-------- |
220 | 209 | # In Python, truthy and falsy values are values that evaluate to True or False in a Boolean context. |
221 | 210 | # Truthy values behave like True, while falsy values behave like False when used in conditions. |
222 | 211 | # Will look more into this topic as I progress |
223 | | - |
| 212 | +""" |
224 | 213 | if 1: |
225 | 214 | print("1 is truthy") |
226 | 215 | if not 0: |
|
231 | 220 | 1 is truthy |
232 | 221 | 0 is falsy |
233 | 222 | """ |
234 | | - |
| 223 | +""" |
235 | 224 | #--------------Set Data Type------------------- |
236 | | - |
237 | 225 | # In Python Data Types, set is an unordered collection of data types that is iterable, mutable and has no duplicate elements. |
238 | 226 | # The order of the elements in a set is undefined though it may consist of various elements. |
239 | 227 |
|
240 | 228 | #--------------Create a set in Python---------- |
241 | | - |
242 | 229 | # Sets can be created by using the built-in set() function |
243 | 230 | # with an iterable object or sequence by placing the sequence inside curly braces, seperated by a comma. |
244 | 231 | # The type of elements in a set need not be the same, various mixed-up data type values can also be passed to the set. |
245 | | - |
| 232 | +""" |
246 | 233 | s1 = set() |
247 | 234 |
|
248 | 235 | s1 = set("setdatatype") |
|
271 | 258 |
|
272 | 259 | # Output would look like: |
273 | 260 | """ |
274 | | -{'python', 'data'} |
| 261 | +{'python', 'data'} |
| 262 | +
|
275 | 263 | data True |
276 | 264 |
|
277 | 265 | """ |
278 | 266 |
|
279 | | -#-----------------Dictionary type data------------- |
280 | | - |
| 267 | +""" |
| 268 | +-----------------Dictionary type data------------- |
281 | 269 | # A dictionary in Python is a collection of data values used to store data values like a map, |
282 | 270 | # Unlike other python data types, a dictionary holds a key: value pair. |
283 | 271 | # key value is provided in a dictionary to make it more optimized. |
284 | 272 | # Each key-value pair in a dictionary is seperated by a colon: |
285 | 273 | # whereas each key is separated by a comma |
286 | 274 |
|
287 | 275 | #---------------Create a Dictionary in Python------- |
288 | | - |
289 | 276 | # Values in a dictionary can be of any datatype and can be duplicated, |
290 | 277 | # Whereas keys cant be repeated and must be immutable |
291 | 278 | # The dictionary can also be created by the built-in function dict() |
292 | 279 | # Dictionary keys are key sensitive |
293 | | - |
| 280 | +""" |
294 | 281 | d = {} |
295 | 282 |
|
296 | 283 | d = {1: "Dict", 2:"in", 3:"Python"} |
|
301 | 288 | d1 = dict({1: "python", 2: "is", 3:"great"}) |
302 | 289 | print(d1) |
303 | 290 |
|
304 | | -#------------Accessing Key-value in Dictionary--- |
305 | | - |
| 291 | +""" |
| 292 | +------------Accessing Key-value in Dictionary--- |
306 | 293 | # In order to access items from a dictionary, refer to its key name |
307 | 294 | # key can be used inside the squre breackets using get() method we can access dictionary elements |
308 | | - |
| 295 | +""" |
309 | 296 | d = {1: "bash", "name": "Python", 3: "nodejs"} |
310 | 297 | print(d["name"]) |
311 | 298 |
|
|
0 commit comments