<jupyter_start><jupyter_text>Table of Contents2.1. Data Types2.1.1. Numbers2.1.2. Boolean2.1.3. Python Strings2.1.4 Python List2.1.5 Python Tuple2.1.6 Python Set2.1.7 Python Dictionary2.2 Conversion between Datatypes  2.1. Data Types  Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.  2.1.1. Numbers Integers, floating point numbers and complex numbers falls under Python numbers category. They are defined as int, float and complex class in Python.We can use the type() function to know which class a variable or a value belongs to and the isinstance() function to check if an object belongs to a particular class.<jupyter_code>a = 5                               #data type is implicitly set to integer
print(a, " is of type", type(a))
a = 2.5                            #data type is changed to float
print(a, " is of type", type(a))
a = 1 + 2j                          #data type is changed to complex number
print(a, " is complex number?") 
print(isinstance(1+2j, complex))
print(type(a))<jupyter_output>(1+2j)  is complex number?
True
<class 'complex'><jupyter_text>2.1.2. Boolean  Boolean represents the truth values False and True<jupyter_code>a = True                          #a is a boolean type
print(type(a))<jupyter_output><class 'bool'><jupyter_text>2.1.3. Python Strings String is sequence of Unicode characters. We can use single quotes or double quotes to represent strings. Multi-line strings can be denoted using triple quotes, ''' or """. A string in Python consists of a series or sequence of characters - letters, numbers, and special characters. Strings can be indexed - often synonymously called subscripted as well. Similar to C, the first character of a string has the index 0.<jupyter_code>s = "This is an introduction to python"

print(s)
print(s[0])
#last char s[len(s)-1] or s[-1]
#slicing
s[5:]<jupyter_output><empty_output><jupyter_text>2.1.4 Python List List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. All the items in a list do not need to be of the same type.Declaring a list is , Items separated by commas are enclosed within brackets [ ].<jupyter_code>a = [10, 20.5, "Hello"]
print(a[1])   #print 1st index element<jupyter_output>20.5<jupyter_text>Lists are mutable, meaning, value of elements of a list can be altered.<jupyter_code>a[1] = 30.7
print(a)<jupyter_output>[10, 30.7, 'Hello']<jupyter_text>2.1.5 Python Tuple Tuple is an ordered sequence of items same as list.The only difference is that tuples are immutable. Tuples once created cannot be modified.<jupyter_code>t = (1, 1.5, "Py")
print(t[1]) #extract particular element
t[1] = 1.25<jupyter_output><empty_output><jupyter_text>2.1.6 Python Set Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { }. Items in a set are not ordered.<jupyter_code>a = {10, 30, 20, 40, 5}
print(a)
print(type(a))             #print type of a
s = {10, 20, 20, 30, 30, 30}
print(s)                    #automatically set won't consider duplicate elements
print(s[1]) #we can't print particular element in set because 
            #it's unorder collections of items<jupyter_output><empty_output><jupyter_text>2.1.7 Python Dictionary Dictionary is an unordered collection of key-value pairs. In Python, dictionaries are defined within braces {} with each item being a pair in the form key:value. Key and value can be of any type.<jupyter_code>d = {'a': "apple", 'b': "bat"}
print(d['a'])<jupyter_output>apple<jupyter_text>2.2 Conversion between Datatypes We can convert between different data types by using different type conversion functions like int(), float(), str() etc.<jupyter_code>float(5)     #convert interger to float using float() method
int(100.5)   #convert float to integer using int() method
str(20)      #convert integer to string<jupyter_output><empty_output><jupyter_text>Conversion to and from string must contain compatible values.<jupyter_code>int('10p')
user = "vishnu"
lines = 100

print("Congratulations, " + user + "! You just wrote " + str(lines) + " lines of code" )
#remove str and gives error<jupyter_output>Congratulations, vishnu! You just wrote 100 lines of code<jupyter_text>We can convert one sequence to other<jupyter_code>a = [1, 2, 3]

print(type(a))      #type of a is list 

s = set(a)          #convert list to set using set() method

print(type(s))      #now type of s is set
list("Hello")       #convert String to list using list() method<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09379727685325265, 'fraction_numerical': 0.028312081262156907, 'mean_word_length': 4.125138427464009, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '94402', 'license': 'Apache-2.0', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1407, 'n_words': 584, 'path': 'python_basics_2.ipynb', 'repo_name': 'SaiTanujaChava/Python', 'size': '4627'}