<jupyter_start><jupyter_text>Introduction to Python Python Keywords and Identifiers  Python KeywordsKeywords are the reserved words in Python.We cannot use a keyword as a variable name, function name or any other identifier. They are used to define the syntax and structure of the Python language.In Python, keywords are case sensitive.There are 33 keywords in Python 3.7. This number can vary slightly over the course of time.  Python IdentifiersAn identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one entity from another.Rules for writing identifiers1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _. Names like myClass, var_1 and print_this_to_screen, all are valid example.2. An identifier cannot start with a digit. 1variable is invalid, but variable1 is a valid name.3. Keywords cannot be used as identifiers.<jupyter_code>global = 1<jupyter_output><empty_output><jupyter_text>4. We cannot use special symbols like !, @, , $, % etc. in our identifier.<jupyter_code>a@ = 0<jupyter_output><empty_output><jupyter_text>5. An identifier can be of any length.Python is a case-sensitive language. This means, `Variable` and `variable` are not the same.Always give the identifiers a name that makes sense. While `c = 10` is a valid name, writing `count = 10` would make more sense, and it would be easier to figure out what it represents when you look at your code after a long gap.Multiple words can be separated using an underscore, like `this_is_a_long_variable`.  Python Statement, Indentation and Comments Python StatementInstructions that a Python interpreter can execute are called statements. For example, `a = 1` is an assignment statement. `if` statement, `for` statement, `while` statement, etc. are other kinds of statements. Multi-line statementIn Python, the end of a statement is marked by a newline character. But we can make a statement extend over multiple lines with the line continuation character (\). For example:<jupyter_code>a = 1 + 2 + 3 + \
    4 + 5 + 6 + \
    7 + 8 + 9<jupyter_output><empty_output><jupyter_text>This is an explicit line continuation. In Python, line continuation is implied inside parentheses `( )`, brackets `[ ]`, and braces `{ }`. For instance, we can implement the above multi-line statement as:<jupyter_code>a = (1 + 2 + 3 +
    4 + 5 + 6 +
    7 + 8 + 9)<jupyter_output><empty_output><jupyter_text>Here, the surrounding parentheses `( )` do the line continuation implicitly. Same is the case with `[ ]` and `{ }`. For example:<jupyter_code>colors = ['red',
          'blue',
          'green']<jupyter_output><empty_output><jupyter_text>We can also put multiple statements in a single line using semicolons, as follows:<jupyter_code>a = 1; b = 2; c = 3<jupyter_output><empty_output><jupyter_text>Python IndentationMost of the programming languages like C, C++, and Java use braces `{ }` to define a block of code. Python, however, uses indentation.A code block (body of a function, loop, etc.) starts with indentation and ends with the first unindented line. The amount of indentation is up to you, but it must be consistent throughout that block.Generally, four whitespaces are used for indentation and are preferred over tabs. Here is an example.<jupyter_code>for i in range(1,11):
    print(i)
    if i == 5:
        break<jupyter_output>1
2
3
4
5<jupyter_text>The enforcement of indentation in Python makes the code look neat and clean. This results in Python programs that look similar and consistent.Indentation can be ignored in line continuation, but it's always a good idea to indent. It makes the code more readable. For example:<jupyter_code>if True:
    print('Hello')
    a = 5<jupyter_output>Hello<jupyter_text>and<jupyter_code>if True: print('Hello'); a = 5<jupyter_output>Hello<jupyter_text>both are valid and do the same thing, but the former style is clearer.Incorrect indentation will result in `IndentationError`.  Python CommentsComments are very important while writing a program. They describe what is going on inside a program, so that a person looking at the source code does not have a hard time figuring it out.You might forget the key details of the program you just wrote in a month's time. So taking the time to explain these concepts in the form of comments is always fruitful.In Python, we use the hash () symbol to start writing a comment.It extends up to the newline character. Comments are for programmers to better understand a program. Python Interpreter ignores comments.<jupyter_code>#This is a comment
#print out Hello
print('Hello')<jupyter_output>Hello<jupyter_text>Another way of doing this is to use triple quotes, either `'''` or `"""`.These triple quotes are generally used for multi-line strings. But they can be used as a multi-line comment as well. Unless they are not docstrings, they do not generate any extra code.<jupyter_code>"""This is also a
perfect example of
multi-line comments"""
print('Hello')<jupyter_output>Hello<jupyter_text>Docstrings in PythonA docstring is short for documentation string.Python docstrings (documentation strings) are the string literals that appear right after the definition of a function, method, class, or module.Triple quotes are used while writing docstrings. For example:<jupyter_code>def double(num):
    """Function to double the value"""
    return 2*num<jupyter_output><empty_output><jupyter_text>Docstrings appear right after the definition of a function, class, or a module. This separates docstrings from multiline comments using triple quotes.The docstrings are associated with the object as their `__doc__` attribute.So, we can access the docstrings of the above function with the following lines of code:<jupyter_code>def double(num):
    """Function to double the value"""
    return 2*num
print(double.__doc__)<jupyter_output>Function to double the value<jupyter_text>Python VariablesA variable is a named location used to store data in the memory. It is helpful to think of variables as a container that holds data that can be changed later in the program. For example,<jupyter_code>number = 10<jupyter_output><empty_output><jupyter_text>Here, we have created a variable named number. We have assigned the value 10 to the variable.You can think of variables as a bag to store books in it and that book can be replaced at any time.<jupyter_code>number = 10
number = 1.1<jupyter_output><empty_output><jupyter_text>Initially, the value of `number` was `10`. Later, it was changed to `1.1`.  Note: In Python, we don't actually assign values to the variables. Instead, Python gives the reference of the object(value) to the variable.   Assigning values to Variables in PythonAs you can see from the above example, you can use the assignment operator `=` to assign a value to a variable.**Example 1: Declaring and assigning value to a variable**<jupyter_code>website = "apple.com"
print(website)<jupyter_output>apple.com<jupyter_text>In the above program, we assigned a value apple.com to the variable website. Then, we printed out the value assigned to website i.e. apple.com Note: Python is a type-inferred language, so you don't have to explicitly define the variable type. It automatically knows that `apple.com` is a string and declares the `website` variable as a string.  **Example 2: Changing the value of a variable**<jupyter_code>website = "apple.com"
print(website)

# assigning a new variable to website
website = "google.com"

print(website)<jupyter_output>apple.com
google.com<jupyter_text>In the above program, we have assigned `apple.com` to the website variable initially. Then, the value is changed to `google.com`. **Example 3: Assigning multiple values to multiple variables**<jupyter_code>a, b, c = 5, 3.2, "Hello"

print (a)
print (b)
print (c)<jupyter_output>5
3.2
Hello<jupyter_text>If we want to assign the same value to multiple variables at once, we can do this as:<jupyter_code>x = y = z = "same"

print (x)
print (y)
print (z)<jupyter_output>same
same
same<jupyter_text>The second program assigns the `same` string to all the three variables `x`, `y` and `z`.  ConstantsA constant is a type of variable whose value cannot be changed. It is helpful to think of constants as containers that hold information which cannot be changed later.You can think of constants as a bag to store some books which cannot be replaced once placed inside the bag.  Assigning value to constant in PythonIn Python, constants are usually declared and assigned in a module. Here, the module is a new file containing variables, functions, etc which is imported to the main file. Inside the module, constants are written in all capital letters and underscores separating the words.**Example 3: Declaring and assigning value to a constant** Create a `constant.py`: ```pythonPI = 3.14GRAVITY = 9.8``` Create a `main.py`: ```python import constantprint(constant.PI)print(constant.GRAVITY) ``` **Output:**```python3.149.8``` In the above program, we create a constant.py module file. Then, we assign the constant value to `PI` and `GRAVITY`. After that, we create a main.py file and import the `constant` module. Finally, we print the constant value.Note: In reality, we don't use constants in Python. Naming them in all capital letters is a convention to separate them from variables, however, it does not actually prevent reassignment.  Rules and Naming Convention for Variables and constants1. Constant and variable names should have a combination of letters in lowercase (**a to z**) or uppercase (**A to Z**) or digits (**0 to 9**) or an underscore (_). For example:```pythonsnake_caseMACRO_CASEcamelCaseCapWords```2. Create a name that makes sense. For example, `vowel` makes more sense than `v`.3. If you want to create a variable name having two words, use underscore to separate them. For example:```pythonmy_namecurrent_salary```4. Use capital letters possible to declare a constant. For example:```pythonPIGMASSSPEED_OF_LIGHTTEMP```5. Never use special symbols like !, @, , $, %, etc.6. Don't start a variable name with a digit.  LiteralsLiteral is a raw data given in a variable or constant. In Python, there are various types of literals they are as follows: Numeric LiteralsNumeric Literals are immutable (unchangeable). Numeric literals can belong to 3 different numerical types: `Integer`, `Float`, and `Complex`. String literalsA string literal is a sequence of characters surrounded by quotes. We can use both single, double, or triple quotes for a string. And, a character literal is a single character surrounded by single or double quotes. Boolean literalsA Boolean literal can have any of the two values: `True` or `False`. Special literalsPython contains one special literal i.e. `None`. We use it to specify that the field has not been created. Literal CollectionsThere are four different literal collections List literals, Tuple literals, Dict literals, and Set literals.**How to use literals collections in Python?**<jupyter_code>fruits = ["apple", "mango", "orange"] #list
numbers = (1, 2, 3) #tuple
alphabets = {'a':'apple', 'b':'ball', 'c':'cat'} #dictionary
vowels = {'a', 'e', 'i' , 'o', 'u'} #set

print(fruits)
print(numbers)
print(alphabets)
print(vowels)<jupyter_output>['apple', 'mango', 'orange']
(1, 2, 3)
{'a': 'apple', 'b': 'ball', 'c': 'cat'}
{'i', 'a', 'o', 'u', 'e'}<jupyter_text>In the above program, we created a `list of fruits`, a `tuple of numbers`, a `dictionary dict` having values with keys designated to each value and a `set of vowels`.  Data types in PythonEvery 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. Python NumbersIntegers, floating point numbers and complex numbers fall under Python numbers category. They are defined as `int`, `float` and `complex` classes in Python.We can use the `type()` function to know which class a variable or a value belongs to. Similarly, the `isinstance()` function is used to check if an object belongs to a particular class.<jupyter_code>a = 5
print(a, "is of type", type(a))

a = 2.0
print(a, "is of type", type(a))

a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))<jupyter_output>5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True<jupyter_text>Python ListList 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 pretty straight forward. Items separated by commas are enclosed within brackets `[ ]`.<jupyter_code>a = [1, 2.2, 'python']<jupyter_output><empty_output><jupyter_text>We can use the slicing operator `[ ]` to extract an item or a range of items from a list. The index starts from 0 in Python.<jupyter_code>a = [5,10,15,20,25,30,35,40]

# a[2] = 15
print("a[2] = ", a[2])

# a[0:3] = [5, 10, 15]
print("a[0:3] = ", a[0:3])

# a[5:] = [30, 35, 40]
print("a[5:] = ", a[5:])<jupyter_output>a[2] =  15
a[0:3] =  [5, 10, 15]
a[5:] =  [30, 35, 40]<jupyter_text>Lists are mutable, meaning, the value of elements of a list can be altered.<jupyter_code>a = [1, 2, 3]
a[2] = 4
print(a)<jupyter_output>[1, 2, 4]<jupyter_text>Python TupleTuple is an ordered sequence of items same as a list. The only difference is that tuples are immutable. Tuples once created cannot be modified.Tuples are used to write-protect data and are usually faster than lists as they cannot change dynamically.It is defined within parentheses `()` where items are separated by commas.<jupyter_code>t = (5,'program', 1+3j)<jupyter_output><empty_output><jupyter_text>We can use the slicing operator `[]` to extract items but we cannot change its value.<jupyter_code>t = (5,'program', 1+3j)

# t[1] = 'program'
print("t[1] = ", t[1])

# t[0:3] = (5, 'program', (1+3j))
print("t[0:3] = ", t[0:3])

# Generates error
# Tuples are immutable
t[0] = 10<jupyter_output>t[1] =  program
t[0:3] =  (5, 'program', (1+3j))<jupyter_text>Python StringsString 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 `"""`.<jupyter_code>s = "This is a string"
print(s)
s = '''A multiline
string'''
print(s)<jupyter_output>This is a string
A multiline
string<jupyter_text>Just like a list and tuple, the slicing operator `[ ]` can be used with strings. Strings, however, are **immutable**.<jupyter_code>s = 'Hello world!'

# s[4] = 'o'
print("s[4] = ", s[4])

# s[6:11] = 'world'
print("s[6:11] = ", s[6:11])

# Generates error
# Strings are immutable in Python
s[5] ='d'<jupyter_output>s[4] =  o
s[6:11] =  world<jupyter_text>Python SetSet 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 = {5,2,3,1,4}

# printing set variable
print("a = ", a)

# data type of variable a
print(type(a))<jupyter_output>a =  {1, 2, 3, 4, 5}
<class 'set'><jupyter_text>We can perform set operations like union, intersection on two sets. Sets have unique values. They eliminate duplicates.<jupyter_code>a = {1,2,2,3,3,3}
print(a)<jupyter_output>{1, 2, 3}<jupyter_text>Since, set are unordered collection, indexing has no meaning. Hence, the slicing operator `[]` **does not work**.  Python DictionaryDictionary is an unordered collection of key-value pairs.It is generally used when we have a huge amount of data. Dictionaries are optimized for retrieving data. We must know the key to retrieve the value.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 = {1:'value','key':2}
type(d)<jupyter_output><empty_output><jupyter_text>We use key to retrieve the respective value. But not the other way around.<jupyter_code>d = {1:'value','key':2}
print(type(d))

print("d[1] = ", d[1]);

print("d['key'] = ", d['key']);

# Generates error
print("d[2] = ", d[2]);<jupyter_output><class 'dict'>
d[1] =  value
d['key'] =  2<jupyter_text>Conversion between data typesWe can convert between different data types by using different type conversion functions like `int()`, `float()`, `str()`, etc.  Type ConversionThe process of converting the value of one data type (integer, string, float, etc.) to another data type is called type conversion. Python has two types of type conversion.1. Implicit Type Conversion2. Explicit Type Conversion**Implicit Type Conversion**In Implicit type conversion, Python automatically converts one data type to another data type. This process doesn't need any user involvement.Let's see an example where Python promotes the conversion of the lower data type (integer) to the higher data type (float) to avoid data loss.**Example 1: Converting integer to float**<jupyter_code>num_int = 123
num_flo = 1.23

num_new = num_int + num_flo

print("datatype of num_int:",type(num_int))
print("datatype of num_flo:",type(num_flo))

print("Value of num_new:",num_new)
print("datatype of num_new:",type(num_new))<jupyter_output>datatype of num_int: <class 'int'>
datatype of num_flo: <class 'float'>
Value of num_new: 124.23
datatype of num_new: <class 'float'><jupyter_text>Now, let's try adding a string and an integer, and see how Python deals with it.**Example 2: Addition of string(higher) data type and integer(lower) datatype**<jupyter_code>num_int = 123
num_str = "456"

print("Data type of num_int:",type(num_int))
print("Data type of num_str:",type(num_str))

print(num_int+num_str)<jupyter_output>Data type of num_int: <class 'int'>
Data type of num_str: <class 'str'><jupyter_text>In the above program,* We add two variables `num_int` and `num_str`.* As we can see from the output, we got TypeError. Python is not able to use Implicit Conversion in such conditions.* However, Python has a solution for these types of situations which is known as Explicit Conversion.**Explicit Type Conversion**In Explicit Type Conversion, users convert the data type of an object to required data type. We use the predefined functions like `int()`, `float()`, `str()`, etc to perform explicit type conversion.This type of conversion is also called typecasting because the user casts (changes) the data type of the objects.Syntax :```python(expression)``` Typecasting can be done by assigning the required data type function to the expression.**Example 3: Addition of string and integer using explicit conversion**<jupyter_code>num_int = 123
num_str = "456"

print("Data type of num_int:",type(num_int))
print("Data type of num_str before Type Casting:",type(num_str))

num_str = int(num_str)
print("Data type of num_str after Type Casting:",type(num_str))

num_sum = num_int + num_str

print("Sum of num_int and num_str:",num_sum)
print("Data type of the sum:",type(num_sum))<jupyter_output>Data type of num_int: <class 'int'>
Data type of num_str before Type Casting: <class 'str'>
Data type of num_str after Type Casting: <class 'int'>
Sum of num_int and num_str: 579
Data type of the sum: <class 'int'><jupyter_text>Note   + Type Conversion is the conversion of object from one data type to another data type.+ Implicit Type Conversion is automatically performed by the Python interpreter.+ Python avoids the loss of data in Implicit Type Conversion.+ Explicit Type Conversion is also called Type Casting, the data types of objects are converted using predefined functions by the user.+ In Type Casting, loss of data may occur as we enforce the object to a specific data type.  Python Input, Output and Import Python Output Using print() functionWe use the `print()` function to output data to the standard output device (screen). We can also output data to a file.Examples:<jupyter_code>print('This sentence is output to the screen')
a = 5
print('The value of a is', a)<jupyter_output>The value of a is 5<jupyter_text>Output formattingSometimes we would like to format our output to make it look attractive. This can be done by using the `str.format()` method. This method is visible to any string object.<jupyter_code>x = 5; y = 10
print('The value of x is {} and y is {}'.format(x,y))
print('I love {0} and {1}'.format('bread','butter'))
print('I love {1} and {0}'.format('bread','butter'))<jupyter_output>I love bread and butter
I love butter and bread<jupyter_text>We can even use keyword arguments to format the string.<jupyter_code>print('Hello {name}, {greeting}'.format(greeting = 'Goodmorning', name = 'John'))<jupyter_output>Hello John, Goodmorning<jupyter_text>Python InputUp until now, our programs were static. The value of variables was defined or hard coded into the source code.To allow flexibility, we might want to take the input from the user. In Python, we have the `input()` function to allow this. The syntax for `input()` is:```pythoninput([prompt])``` where `prompt` is the string we wish to display on the screen. It is optional.<jupyter_code>num = input('Enter a number: ')
num<jupyter_output><empty_output><jupyter_text>Here, we can see that the entered value `10` is a string, not a number. To convert this into a number we can use `int()` or `float()` functions.<jupyter_code>int('10')

float('10')<jupyter_output><empty_output><jupyter_text>This same operation can be performed using the `eval()` function. But `eval` takes it further. It can evaluate even expressions, provided the input is a string<jupyter_code>int('2+3')
eval('2+3')<jupyter_output><empty_output><jupyter_text>Python ImportWhen our program grows bigger, it is a good idea to break it into different modules.A module is a file containing Python definitions and statements. Python modules have a filename and end with the extension `.py`.Definitions inside a module can be imported to another module or the interactive interpreter in Python. We use the `import` keyword to do this.For example, we can import the `math` module by typing the following line:<jupyter_code>import math
print(math.pi)<jupyter_output>3.141592653589793<jupyter_text>While importing a module, Python looks at several places defined in `sys.path`. It is a list of directory locations.<jupyter_code>import sys
sys.path<jupyter_output><empty_output><jupyter_text>Operators in pythonOperators are special symbols in Python that carry out arithmetic or logical computation. The value that the operator operates on is called the operand.For example:<jupyter_code>2+3<jupyter_output><empty_output><jupyter_text>Here, `+` is the operator that performs addition. `2` and `3` are the operands and `5` is the output of the operation. Arithmetic operators in PythonArithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc.<jupyter_code>x = 15
y = 4

# Output: x + y = 19
print('x + y =',x+y)

# Output: x - y = 11
print('x - y =',x-y)

# Output: x * y = 60
print('x * y =',x*y)

# Output: x / y = 3.75
print('x / y =',x/y)

# Output: x // y = 3
print('x // y =',x//y)

# Output: x ** y = 50625
print('x ** y =',x**y)<jupyter_output>x + y = 19
x - y = 11
x * y = 60
x / y = 3.75
x // y = 3
x ** y = 50625<jupyter_text>Comparison operatorsComparison operators are used to compare values. It returns either `True` or `False` according to the condition.<jupyter_code>x = 10
y = 12

# Output: x > y is False
print('x > y is',x>y)

# Output: x < y is True
print('x < y is',x<y)

# Output: x == y is False
print('x == y is',x==y)

# Output: x != y is True
print('x != y is',x!=y)

# Output: x >= y is False
print('x >= y is',x>=y)

# Output: x <= y is True
print('x <= y is',x<=y)<jupyter_output>x > y is False
x < y is True
x == y is False
x != y is True
x >= y is False
x <= y is True<jupyter_text>Logical operatorsLogical operators are the `and`, `or`, `not` operators.<jupyter_code>x = True
y = False

print('x and y is',x and y)

print('x or y is',x or y)

print('not x is',not x)<jupyter_output>x and y is False
x or y is True
not x is False<jupyter_text>Bitwise operatorsBitwise operators act on operands as if they were strings of binary digits. They operate bit by bit, hence the name.For example, `2` is `10` in binary and `7` is `111`. Assignment operatorsAssignment operators are used in Python to assign values to variables.`a = 5` is a simple assignment operator that assigns the value 5 on the right to the variable a on the left.There are various compound operators in Python like `a += 5` that adds to the variable and later assigns the same. It is equivalent to `a = a + 5`. Special operatorsPython language offers some special types of operators like the identity operator or the membership operator. They are described below with examples. Identity operators`is` and `is not` are the identity operators in Python. They are used to check if two values (or variables) are located on the same part of the memory. Two variables that are equal does not imply that they are identical.<jupyter_code>x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1,2,3]
y3 = [1,2,3]

# Output: False
print(x1 is not y1)

# Output: True
print(x2 is y2)

# Output: False
print(x3 is y3)<jupyter_output>False
True
False<jupyter_text>Membership operators`in` and `not in` are the membership operators in Python. They are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary).In a dictionary we can only test for presence of key, not the value.<jupyter_code>x = 'Hello world'
y = {1:'a',2:'b'}

# Output: True
print('H' in x)

# Output: True
print('hello' not in x)

# Output: True
print(1 in y)

# Output: False
print('a' in y)<jupyter_output>True
True
True
False<jupyter_text>Python if...else StatementDecision making is required when we want to execute a code only if a certain condition is satisfied.The `if…elif…else` statement is used in Python for decision making.**Python if Statement Syntax**```pythonif test expression:    statement(s)```<jupyter_code># If the number is positive, we print an appropriate message

num = 3
if num > 0:
    print(num, "is a positive number.")
print("This is always printed.")

num = -1
if num > 0:
    print(num, "is a positive number.")
print("This is also always printed.")<jupyter_output>3 is a positive number.
This is always printed.
This is also always printed.<jupyter_text>Python if...else Statement**Syntax of if...else**```pythonif test expression:    Body of ifelse:    Body of else```<jupyter_code># Program checks if the number is positive or negative
# And displays an appropriate message

num = 3

# Try these two variations as well. 
# num = -5
# num = 0

if num >= 0:
    print("Positive or Zero")
else:
    print("Negative number")<jupyter_output>Positive or Zero<jupyter_text>Python if...elif...else Statement**Syntax of if...elif...else**```pythonif test expression:    Body of ifelif test expression:    Body of elifelse:     Body of else```<jupyter_code>'''In this program, 
we check if the number is positive or
negative or zero and 
display an appropriate message'''

num = 3.4

# Try these two variations as well:
# num = 0
# num = -4.5

if num > 0:
    print("Positive number")
elif num == 0:
    print("Zero")
else:
    print("Negative number")<jupyter_output>Positive number<jupyter_text>Python Nested if statementsWe can have a `if...elif...else` statement inside another `if...elif...else` statement. This is called nesting in computer programming.Any number of these statements can be nested inside one another. Indentation is the only way to figure out the level of nesting. They can get confusing, so they must be avoided unless necessary.<jupyter_code>'''In this program, we input a number
check if the number is positive or
negative or zero and display
an appropriate message
This time we use nested if statement'''

num = float(input("Enter a number: "))
if num >= 0:
    if num == 0:
        print("Zero")
    else:
        print("Positive number")
else:
    print("Negative number")
'''In this program, we input a number
check if the number is positive or
negative or zero and display
an appropriate message
This time we use nested if statement'''

num = float(input("Enter a number: "))
if num >= 0:
    if num == 0:
        print("Zero")
    else:
        print("Positive number")
else:
    print("Negative number")
'''In this program, we input a number
check if the number is positive or
negative or zero and display
an appropriate message
This time we use nested if statement'''

num = float(input("Enter a number: "))
if num >= 0:
    if num == 0:
        print("Zero")
    else:
        print("Positive number")
else:
    print("Negative number")<jupyter_output>Enter a number: 0
Zero<jupyter_text>Python for LoopThe for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects. Iterating over a sequence is called traversal.**Syntax of for Loop**```pythonfor val in sequence:	Body of for```Here, `val` is the variable that takes the value of the item inside the sequence on each iteration.Loop continues until we reach the last item in the sequence. The body of for loop is separated from the rest of the code using indentation.<jupyter_code># Program to find the sum of all numbers stored in a list

# List of numbers
numbers = [6, 5, 3, 8, 4, 2, 5, 4, 11]

# variable to store the sum
sum = 0

# iterate over the list
for val in numbers:
	sum = sum+val

print("The sum is", sum)<jupyter_output>The sum is 48<jupyter_text>The range() functionWe can generate a sequence of numbers using `range()` function. `range(10)` will generate numbers from 0 to 9 (10 numbers).We can also define the start, stop and step size as `range(start, stop,step_size)`. step_size defaults to 1 if not provided.The `range` object is "lazy" in a sense because it doesn't generate every number that it "contains" when we create it. However, it is not an iterator since it supports `in`, `len` and `__getitem__` operations.This function does not store all the values in memory; it would be inefficient. So it remembers the start, stop, step size and generates the next number on the go.To force this function to output all the items, we can use the function `list()`.example:<jupyter_code>print(range(10))

print(list(range(10)))

print(list(range(2, 8)))

print(list(range(2, 20, 3)))<jupyter_output>range(0, 10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 3, 4, 5, 6, 7]
[2, 5, 8, 11, 14, 17]<jupyter_text>We can use the `range()` function in `for` loops to iterate through a sequence of numbers. It can be combined with the `len()` function to iterate through a sequence using indexing.<jupyter_code># Program to iterate through a list using indexing

genre = ['pop', 'rock', 'jazz']

# iterate over the list using index
for i in range(len(genre)):
	print("I like", genre[i])<jupyter_output>I like pop
I like rock
I like jazz<jupyter_text>for loop with elseA `for` loop can have an optional `else` block as well. The `else` part is executed if the items in the sequence used in for loop exhausts.The `break` keyword can be used to stop a for loop. In such cases, the else part is ignored.Hence, a for loop's else part runs if no break occurs.<jupyter_code>digits = [0, 1, 5]

for i in digits:
    print(i)
else:
    print("No items left.")
# program to display student's marks from record
student_name = 'Soyuj'

marks = {'James': 90, 'Jules': 55, 'Arthur': 77}

for student in marks:
    if student == student_name:
        print(marks[student])
        break
else:
    print('No entry with that name found.')<jupyter_output>No entry with that name found.
{'fraction_non_alphanumeric': 0.09709414709890041, 'fraction_numerical': 0.015464080869537662, 'mean_word_length': 4.895385764991594, 'pattern_counts': {'":': 0, '<': 210, '<?xml version=': 0, '>': 217, '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': '57', 'dir': 'jupyter-structured-clean-dedup', 'id': '412454', 'license': 'MIT', 'n_tokens_mistral': 9803, 'n_tokens_neox': 9285, 'n_words': 4318, 'path': 'jupyter_notebooks/bigdata/python-nbk/pythonnbk/Intro2python.ipynb', 'repo_name': 'Aish-15/gcrnet.github.io', 'size': '31557'}