<jupyter_start><jupyter_text>Introduction to PythonLet's have a look at Python as a language and what features does it bring to be among the top 3 coding languages in the world.<jupyter_code># 1. Unlike other languages Python program works on an Interpreter so to run a code all you have to do is type it out
print("Welcome to upGrad")
# 2. Python language runs line by line, so incase you want to update a piece of code all you have to do is 
#    update the line let's see how -
#Imaginary giraffe
print("O    ")
print("|    ")
print("|____")
print(" ||||")
print(" ||||")
#Let's add another print statement 
print("$" * 3)<jupyter_output>$$$<jupyter_text>Now let's see what happened here  - Any character whether it be numeric or text enclosed within " " or ' '  gets considered as a string; A string is a data type which contains a series of charactersJust like string, there are numerous types of variables in Python; let's have a look  VariablesPython variables are a container that can store any type of value and of any particular size.Unlike other languages such as C, Java - Variables in Python don't need initialization. Let's create a variable to see how do they work<jupyter_code>var1 = "Mike"
print(var1)
var2 = 6
print(var2)<jupyter_output>6<jupyter_text>Now that we know how to store a variable in Python let's try getting input from a user and storing it in Python<jupyter_code>#To get a input from a user we would use the 'input' function
number = input("What's your favourite number? ")
print(number)
#Let's try taking adding a string to the answer received
name = input("Enter your name : ")
print("Welcome", name)
#That was helpful, could I also perform operation on input received?
age = input("Enter your age : ")
print("You are " , age*12 , " months old")<jupyter_output>Enter your age : 33
You are  333333333333333333333333  months old<jupyter_text>age = input("enter your age ")age = int(age)print("You are " , age*12 , " months old")Changing the the of variables type is called typecasting  How to find the Data Type for a variables in Python Here in the below piece of code you can see that we have assigned each variable with a particular value and use the type method we can check the datatype of the variable<jupyter_code>integer_num = 1
floating_num = 1.3
string = 'Mike'
boolean = True

print (type(integer_num))
print (type(floating_num))
print (type(string))
print (type(boolean))<jupyter_output><class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'><jupyter_text>- Type Casting in Python<jupyter_code># Now let us try taking an 
a = 1
print ( bool(a))
print ( float(a))
print ( str(a))<jupyter_output>True
1.0
1<jupyter_text>Arithmatic Operations<jupyter_code>#
a = 6
b = 7
print("Addition  = ", a + b)  
print("Substraction = ", a - b) 
print("Multiplication = ", a * b) 
print("Division = ", a / b)
print("Floor Division = ", a // b) 
print("Modulus or remainder",a % b) 
print("Exponential = ", a ** b)<jupyter_output>Addition  =  13
Substraction =  -1
Multiplication =  42
Division =  0.8571428571428571
Floor Division =  0
Modulus or remainder 6
Exponential =  279936<jupyter_text>Now if you recall that the mathematical  operators follow a precedence rule called PEDMAS -Wherein the fist P is parenthesis, then it's E for exponents, M for multiplication, then D for division, A for addition and finally S for subtraction.Reference - [Python operator precedence](https://docs.python.org/3.7/reference/expressions.html?operator-precedence)<jupyter_code>print((4 * 5) - 9 + 6 / 7)<jupyter_output>11.857142857142858<jupyter_text>String Operations We should look at strings as a banner where multiple characters are linked together. The string data is an immutable type which means it cannot be modified.<jupyter_code>#Whenever we are assigning a char or string we use '' which represents a character
c = 'z'
d = 'Mike'
#You can also use " " double quotes instead of single quotes for strings
e = "John"
#Now when we want to include words with a single quote such as "didn't", "I'll".. we might end up with a error
print('I didn't know that')



#Now to solve this we can use an escape character like 
print('I didn\'t know that')
# Or we can use double quotes
print("I didn't know that")
#Now that '\' escape character which we saw earlier can also be used for other stuff like adding a new line
print("Hi Bob \n\nHow are you?")<jupyter_output>Hi Bob 

How are you?<jupyter_text>Now apart adding new lines to a string we can also add another to a pre-existing string, let's see how -String Concatenation<jupyter_code>#Let's try building a system that could ask for flavour, and the type of desert user wants
flavour=input("What flavour would you like ")
dessert_type=input("What type of dessert would you like ")
print("You have ordered", flavour+"-"+dessert_type)<jupyter_output>What flavour would you like Chocolate
What type of dessert would you like Pudding
You have ordered Chocolate-Pudding<jupyter_text>Congrats on building a simple app using input and string functions. Let's take a step ahead and learn more about string manipulation String Manipulation  Indexing In Strings - Forward indexing starts with 0- Reverse indexing starts with the last character as -1 in a python string- Strings are immutable which, means they cannot be changed once created.- Strings can be modified by slicing a part of it and concatenating with another<jupyter_code># Len() function
string = "I have not failed. I’ve just found 10,000 ways that won’t work. – <NAME>"
len(string)
#Accessing first character
string[-82]
#Accessing last character using negative indexing
string[-1] 
# Trying to change the character at index 2
string[2] = 't'

# Changing the entire string or say changing the label of it
string = 'I have not failed. I’ve just found 10,000 ways that won’t work.” – Einstien'
print (string)<jupyter_output>I have not failed. I’ve just found 10,000 ways that won’t work.” – Einstien<jupyter_text>Slicing In Strings- string[start:end:step]<jupyter_code>#slicing by specifying start and end index
statement = "I have not failed. I’ve just found 10,000 ways that won’t work. – <NAME>"
sliced_statement = statement[0:64]
print(sliced_statement)
batch = "5 girls 3 boys in a class"
girls = batch[ :8]
print(girls)

print(batch[ 8: ])
# Membership 
String = "John! Did you attend the conference on advanced machine learning"
print( 'Lincoln' in String)
print ( 'Behzad' not in String)<jupyter_output>False
True<jupyter_text>String methods- upper()- lower()- strip()- count(substring,begin,end)- https://docs.python.org/3.7/library/stdtypes.htmlstring-methods<jupyter_code># upper() 
small = "i am upper cased"
print(small.upper())
# lower() 
large = "I AM LOWER CASED"
print(large.lower())
# rstrip () function
some_sentence = "There is a space at the end    "
print(some_sentence)
print(some_sentence.rstrip())
increment = '4%'
print(increment.rstrip('%')) 
# lstrip() function
start = "   There is space at the start"
print(start)
print(start.lstrip())
# strip() function 
spaces = "   Trim whitespaces  "
print(spaces)
print(spaces.strip())
num_with_chars = '******444#######'
print(num_with_chars.rstrip('#').lstrip('*'))
#count() Method
string = "This is a sample sentence"
print(string.count('i'))
print(string.count('i',5))
#r/R It is used to specify the raw string.% It is used to perform string formatting.

A = "Data"
B = "Analysis"
C = "Pandas"

print("{0} {1} using {2}".format(A,B,C))

#Now there are a plenty of other string operations available in Python you could explore those using - 
help(str)
#Ignore the methods with a double underscore, for now, those are called the magic methods and we have seen enough magic for the day to be a Python Wizard!!<jupyter_output>Help on class str in module builtins:

class str(object)
 |  str(object='') -> str
 |  str(bytes_or_buffer[, encoding[, errors]]) -> str
 |  
 |  Create a new string object from the given object. If encoding or
 |  errors is specified, then the object must expose a data buffer
 |  that will be decoded using the given encoding and error handler.
 |  Otherwise, returns the result of object.__str__() (if defined)
 |  or repr(object).
 |  encoding defaults to sys.getdefaultencoding().
 |  errors defaults to 'strict'.
 |  
 |  Methods defined here:
 |  
 |  __add__(self, value, /)
 |      Return self+value.
 |  
 |  __contains__(self, key, /)
 |      Return key in self.
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __format__(...)
 |      S.__format__(format_spec) -> str
 |      
 |      Return a formatted version of S as described by format_spec.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getatt[...]
{'fraction_non_alphanumeric': 0.09956461961503207, 'fraction_numerical': 0.016842346471127406, 'mean_word_length': 4.535193405199746, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 47, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '650184', 'license': 'MIT', 'n_tokens_mistral': 2809, 'n_tokens_neox': 2630, 'n_words': 1132, 'path': 'Course_1-PreLaunch_Preparatory_Content/Module_1-Introduction_to_Python_Programming/1-Basics_of_Python/Session.ipynb', 'repo_name': 'Mathews-Tom/MSc_in_Machine_Learning_and_Artificial_Intelligence', 'size': '8748'}