<jupyter_start><jupyter_text>The Zen Of Python<jupyter_code>import this<jupyter_output>The Zen of Python, by <NAME>

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!<jupyter_text>Variables A name that is used to refer to an object is called a variable. In Python, variables can be declared and values can be assigned to it as follows:<jupyter_code>x = 2
y = 5
xy = 'Hey'
x + y, xy<jupyter_output><empty_output><jupyter_text>Multiple variables can be assigned with the same value.<jupyter_code>x = y = 1
x, y<jupyter_output><empty_output><jupyter_text>Operators  Arithmetic Operators | Symbol | Task Performed ||----|---|| +  | Addition || -  | Subtraction || /  | division || %  | mod || *  | multiplication || //  | floor division || **  | to the power of |<jupyter_code>1+2
2-1
1*2
1/2
1/2.0
15%10<jupyter_output><empty_output><jupyter_text>Floor division with `//` gives you the floor of the division result:<jupyter_code>3 // 2<jupyter_output><empty_output><jupyter_text>Relational Operators | Symbol | Task Performed ||----|---|| == | True, if it is equal || !=  | True, if not equal to || < | less than || > | greater than || <=  | less than or equal to || >=  | greater than or equal to |<jupyter_code>z = 1
z == 1
z > 1<jupyter_output><empty_output><jupyter_text>Bitwise Operators | Symbol | Task Performed ||----|---|| &  | Logical And || l  | Logical OR || ^  | XOR || ~  | Negate || >>  | Right shift || <<  | Left shift |<jupyter_code>a = 0b10 # decimal 2
b = 0b11 # decimal 3
a & b
bin(a&b)
5 >> 1<jupyter_output><empty_output><jupyter_text>`0000 0101` -> 5 Shifting the digits by 1 to the right and zero padding`0000 0010` -> 2<jupyter_code>5 << 1<jupyter_output><empty_output><jupyter_text>`0000 0101` -> 5 Shifting the digits by 1 to the left and zero padding`0000 1010` -> 10  Built-in Functions Python comes loaded with pre-built functions  Conversion from one system to another Conversion from hexadecimal to decimal is done by adding prefix `0x` to the hexadecimal value or vice versa by using built in `hex( )`, Octal to decimal by adding prefix `0` to the octal value or vice versa by using built in function `oct( )`.<jupyter_code>hex(170)
0xAA
oct(8)
0b10<jupyter_output><empty_output><jupyter_text>`int( )` accepts two values when used for conversion, one is the value in a different number system and the other is its base. Note that input number in the different number system should be of string type.<jupyter_code>int('010',8), int('0xaa',16), int('1010',2)<jupyter_output><empty_output><jupyter_text>`int( )` can also be used to get only the integer value of a float number or can be used to convert a number which is of type string to integer format. Similarly, the function `str( )` can be used to convert the integer back to string format<jupyter_code>int(7.7), int('7')<jupyter_output><empty_output><jupyter_text>Also note that function `bin( )` is used for binary and `float( )` for decimal/float values. `chr( )` is used for converting ASCII to its alphabet equivalent, `ord( )` is used for the other way round.<jupyter_code>chr(98)
ord('b')<jupyter_output><empty_output><jupyter_text>Simplifying Arithmetic Operations `round( )` function rounds the input value to a specified number of places or to the nearest integer.<jupyter_code>round(5.6231), round(4.55892, 2)<jupyter_output><empty_output><jupyter_text>`complex( )` is used to define a complex number and `abs( )` outputs the absolute value of the same.<jupyter_code>c = complex('5+2j')
abs(c)<jupyter_output><empty_output><jupyter_text>`divmod(x,y)` outputs the quotient and the remainder in a tuple(you will be learning about it in the further chapters) in the format (quotient, remainder).<jupyter_code>divmod(9,2)<jupyter_output><empty_output><jupyter_text>`isinstance( )` returns True, if the first argument is an instance of that class. Multiple classes can also be checked at once.<jupyter_code>isinstance(1, int)
isinstance(1.0,int)
isinstance(1.0,(int,float))<jupyter_output><empty_output><jupyter_text>`cmp(x,y)`|x ? y|Output||---|---|| x < y | -1 || x == y | 0 || x > y | 1 | `pow(x,y,z)` can be used to find the power $x^y$ also the mod of the resulting value with the third specified number can be found i.e. : ($x^y$ % z).<jupyter_code>pow(3,3), pow(3,3,5)<jupyter_output><empty_output><jupyter_text>`range( )` generates the sequence of integers of the specified range. It can also be used to generate a series by specifying the difference between the two numbers within a particular range. The elements are lazily generated, and will only be generated on demand (e.g. by passing them to the `list` constructor):<jupyter_code>range(5)
list(range(5))
list(range(2, 9))
list(range(2,27,8))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11058566751546017, 'fraction_numerical': 0.025100036376864313, 'mean_word_length': 5.096452328159645, 'pattern_counts': {'":': 0, '<': 80, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '635785', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1752, 'n_words': 675, 'path': '01.ipynb', 'repo_name': 'abingham/Python-Lectures', 'size': '5502'}