Skip to content

Commit a3163a6

Browse files
Neatened up the data_types.py file for cleaner output and readability
1 parent 6da7831 commit a3163a6

1 file changed

Lines changed: 23 additions & 36 deletions

File tree

basics/data_types.py

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
print("Lets learn Data Types with Python")
2-
#-------------------------------------------------
1+
"""
32
# Data Types with Python
43
#-------------------------------------------------
5-
64
# Data types in python are a way to classify data items
75
# They represent the kind of value, which determines what operations can be performed on the data
86
# Since everything is an object in python programming
97
# Python data types are classes and variables are instances (objects) of those classes
10-
8+
"""
119

1210
"""
1311
The following are standard or built in data types in Python:
@@ -35,14 +33,11 @@
3533
"""
3634
('python', 'for', 'aws')
3735
38-
"""
39-
40-
# Numeric Data Types
41-
36+
Numeric Data Types
4237
# python numbers represent data that has a numeric value
4338
# A numeric value can be an integer , a floating number or even a complex number
4439
# These values are defined as int, float and complex classes
45-
"""
40+
4641
Integers: value is represented by int class. It contains positive or negative whole numbers (without fractions or decimals).
4742
There is no limit to how long an integer value can be.
4843
@@ -54,7 +49,6 @@
5449
It is specified as (real part) + (imaginary part)j.
5550
For example - 2+3j
5651
57-
5852
"""
5953
a = 5
6054
print(type(a))
@@ -93,10 +87,8 @@
9387
s
9488
9589
"""
96-
97-
#---------------LIST-DATA-TYPE----------------
98-
9990
"""
91+
---------------LIST-DATA-TYPE----------------
10092
Lists are similar to arrays found in other languages.
10193
They are an ordered and mutable collection of items.
10294
It is very flexible as items in a list do not need to be of the same type.
@@ -125,10 +117,8 @@
125117
['byte', 'gb', 1, 4, 5]
126118
127119
"""
128-
129-
130-
#------------- Access List Items-----------------
131120
"""
121+
#------------- Access List Items-----------------
132122
In order to access the list items refer to index number.
133123
In Python, negative sequence indexes represent positions from end of the array.
134124
Negative indexing means beginning from end
@@ -154,9 +144,8 @@
154144
python
155145
"""
156146

157-
158-
#--------------Tuple Data Type-------------------
159147
"""
148+
--------------Tuple Data Type-------------------
160149
Tuple is an ordered collection of Python objects.
161150
The only difference between a tuple and a list is that tuples are immutable.
162151
Tuples cannot be modified after it is created.
@@ -200,12 +189,12 @@
200189
201190
"""
202191

203-
#------------------Boolean Data Type-------------
204-
192+
"""
193+
------------------Boolean Data Type-------------
205194
# Python Boolean Data type is one of the two built-in values, True or False.
206195
# Boolean objects that are equal to True are truthy (true) and those equal to False are falsy (false).
207196
# 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+
"""
209198
print(type(True))
210199
print(type(False))
211200

@@ -215,12 +204,12 @@
215204
<class 'bool'>
216205
217206
"""
218-
#----------------Truthy and Falsy Values--------
219-
207+
"""
208+
----------------Truthy and Falsy Values--------
220209
# In Python, truthy and falsy values are values that evaluate to True or False in a Boolean context.
221210
# Truthy values behave like True, while falsy values behave like False when used in conditions.
222211
# Will look more into this topic as I progress
223-
212+
"""
224213
if 1:
225214
print("1 is truthy")
226215
if not 0:
@@ -231,18 +220,16 @@
231220
1 is truthy
232221
0 is falsy
233222
"""
234-
223+
"""
235224
#--------------Set Data Type-------------------
236-
237225
# In Python Data Types, set is an unordered collection of data types that is iterable, mutable and has no duplicate elements.
238226
# The order of the elements in a set is undefined though it may consist of various elements.
239227
240228
#--------------Create a set in Python----------
241-
242229
# Sets can be created by using the built-in set() function
243230
# with an iterable object or sequence by placing the sequence inside curly braces, seperated by a comma.
244231
# 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+
"""
246233
s1 = set()
247234

248235
s1 = set("setdatatype")
@@ -271,26 +258,26 @@
271258

272259
# Output would look like:
273260
"""
274-
{'python', 'data'}
261+
{'python', 'data'}
262+
275263
data True
276264
277265
"""
278266

279-
#-----------------Dictionary type data-------------
280-
267+
"""
268+
-----------------Dictionary type data-------------
281269
# A dictionary in Python is a collection of data values used to store data values like a map,
282270
# Unlike other python data types, a dictionary holds a key: value pair.
283271
# key value is provided in a dictionary to make it more optimized.
284272
# Each key-value pair in a dictionary is seperated by a colon:
285273
# whereas each key is separated by a comma
286274
287275
#---------------Create a Dictionary in Python-------
288-
289276
# Values in a dictionary can be of any datatype and can be duplicated,
290277
# Whereas keys cant be repeated and must be immutable
291278
# The dictionary can also be created by the built-in function dict()
292279
# Dictionary keys are key sensitive
293-
280+
"""
294281
d = {}
295282

296283
d = {1: "Dict", 2:"in", 3:"Python"}
@@ -301,11 +288,11 @@
301288
d1 = dict({1: "python", 2: "is", 3:"great"})
302289
print(d1)
303290

304-
#------------Accessing Key-value in Dictionary---
305-
291+
"""
292+
------------Accessing Key-value in Dictionary---
306293
# In order to access items from a dictionary, refer to its key name
307294
# key can be used inside the squre breackets using get() method we can access dictionary elements
308-
295+
"""
309296
d = {1: "bash", "name": "Python", 3: "nodejs"}
310297
print(d["name"])
311298

0 commit comments

Comments
 (0)