Skip to main content

Intro To Python And Operators.

 Intro To Python And Operators.



Innomatics Research Labs 

Im a innomatics student, this is for innomatics research labs notes (the best institute of hyderabad) once search in google, course = data science and full stack development


Innomatics Research Labs is a pioneer in “Transforming Career and Lives” of individuals in the Digital Space by catering advanced training on IBM Certified Data Science, Python, IBM Certified Predictive Analytics Modeler, Machine Learning, Artificial Intelligence (AI), Full-stack web development, Amazon Web Services (AWS), DevOps, Microsoft Azure, Big data Analytics, Digital Marketing, and Career Launching program for students who are willing to showcase their skills in the competitive job market with valuable credentials, and also can complete courses with a certificate.


intro to jupyter notebook : 


  • jupyter is an incredibly powerful tool for interactive coding and presenting/documenting our projects.

  • jupyter is an IDE typically used to develop data analysis and data science solutions. Jupyter, in its early days was called IPython(Hence the extension - ipynb) but it was changed to Jupyter to reflect the inclusion of support for other programming languages. It actually provides support for 40+ languages. The name Jupyter is an amalgamation of the major programming languages it supports - JUlia PYTon E R

  • debugging in jupyter is easier compared to other ides like pycharm or spyder, as we have cells in jupyter notebook.

  • jupyter's markdown has the provision to include media like images, video and audio. The features in markdown borrow elements from html(tags).


Markdown : 


ype Markdown and LaTeX: 2

lists or bullet points

unordered lists or bullet points

  • 1st item
    • abc
  • 2nd item
  • 3rd item

ordered lists or bullet points


  1. 1st point

  2. 2nd poin

  3. 3rd point

Type Markdown and LaTeX: 

bold, italic and underlined


text in bold

text in itallic

text is underlined


block qoute


self explainable

> Hi

highlight

enclose the text within ` ` to highlight it

Holla! Amigos

Type Markdown and LaTeX: 

syntax for hyperlink

[Text to be used as hyperlink]< noSpace >(url)



Python


Ex ;

print('Hello World')
print("I'm new to world of python and Data Science")

outputHello World
I'm new to world of python and Data Science

quick galnce of python
  • python is an interpreter, high-level multipurpose programming lang.

  • in python, we use indentation as way to define the scope. whereas other langs use '{ < lines of code > } to define the scope.


> in c, for(a=1; a++' a<10){
            printf("%d", a);
  }

  > in python, for a in range(1,10):
                  print(a)
        
* new line of code in python is defined simply by a new line. no need to use ';' to define the end of the line or statment.

  > in c, `printf("Hi");`

  > in python, `print('Hi')`

Python vs R

  • python can be scaled up with data, which isn't possible in R
  • avaliability of open source libraries that are desgined for specific industry based tasks are more when compared to R.
  • when it comes to deep learning, python beats R. Most of the Data Science libraries are developed with python in mind.

Variables and Literals

Literals
  • Literals are data values which convey information. some of the literal in python are:

    • integer literals: 5 or 10 or any integer
    • string literals: "Hi" or "Hello" or sequence of chars enclosed in qoutes
    • boolean literals: True or False
    • float literals: 5.5 or 10.121645 or any decimal value

Variables
  • variables are more like pointers that points to memory location of our literals or data.

Naming convention of variables:

1) a variable should start with an alphabet or an underscore( _ )

2) we can't have a variable name that starts with a number or special char other than an underscore

3)variable name can't have space in it.

4) Never use a word which changes color after pressing space as a variuable name, these words have a different purpose or meaning or task assigned to them like str, list, tuple, int etc

  • we use = to assign a variable name to literal

Type Markdown and LaTeX: 

Ex :

x = 6 # variable declaration
y = 7
z = 8
print(x)
print(y)
print(z)

Output : 6
              7
              8

  • Note:
  1. unlike other languages, in python, at time of variable declaration one doesn't need to be specified what kind of data type we are providing.

  2. in python, same variable can hold different values at different times, this isn't possible in c++ or java.

Ex : 

a = 5
print(a, type(a))
a = 5.5
print(a, type(a))
a = 'hi'
print(a, type(a))

Output5 <class 'int'>
5.5 <class 'float'>
hi <class 'str'>

comments

  • comments are used to write or include a quick notes in our code
  • in python, comments are of two types, single line comments and multiple line comments
  • single line comments are not executed at time of execution whereas the multiple line comments are executed.
  • multiple line comments are used for documentation purpose. like doc-strings

single line comment
  • a single line comment starts with #
# comment - 1 
# comment - 2 
# comment - 3

multiple line comments
  • multi line comments are enclosed in triple single qoutes or triple double qoutes( ''' or """)
Ex ;

'''line-1
line-2
line-2'''
Output'line-1\nline-2\nline-2'

Data Types in python

* numerical data types

  * int -- 5, 11, -1
  * float -- 11.11, -22.22, 1.87e-20
  * complex -- 3+5j, 5-3j

* sequential data types

  * strings -- 'hi', "hello", """123""", '''0.001'''
  * lists -- [1, 2, 'a', 1.5]
  * tuples -- (11, 'abc', 3+7j)
  
* `dictionaries` (from python version 3.7.0, they are ordered) -- {'key1':'value_1'}

* sets -- (1,4,5,6) -- unordered

* boolean -- True, False

* range

Ex ;

# type() is used to check the data type or the class the particular object belongs to
x = 5
print(x, type(x))

Output 5 <class 'int'>


keywords

* keywords have a special purpose or task associated with them.
* we can't use keywords as names for our variables.
* apart from `True`, `False` and `None`, every other keyword starts with a small case alphabet.

Ex;

import keyword
from keyword import kwlist

print(f'''keywords in python are:
{kwlist} hihdiah''')

#print('keywords in python are \n', kwlist)

print()

print(f'''total number of keywords in python are {len(kwlist)}''')

Output ; keywords in python are;
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

total number of keywords in python are 35

Assigning values


Ex ; a = b  = c = 10
print(a) 
print(b)
print(c)  
Output ;10
10
10

 Operators and operations

* Arthimatics operators
* Comparission Operators
  * Relational operators
  * Logical operators
* Bitwise operators
* Identity operators
* Assignment operators
* Membership operators

Arthimatics operators

[+, -, *, /, //, %, ** ]


x,y = 10,25
# addition
x+y 
35

# subraction
x-y
-15

# multiplication
x*y
250

# floor division '//' gives us the quotient
y//x
2

# % gives the reminder
y%x
5

# division
y/x
2.5

# power
y**x
95367431640625

Comparission operators


Relational operators

[>, <, >=, <=, ==, !=]

  • output of relational operators is a boolean value {True or False}

Ex ;

x,y,z = 10, 11, 11
print(f'values of x, y, z are {x}, {y} and {z} respectivly')
print(f'{x} < {y}: {x < y}')
print(f'{x} > {y}: {x > y}')
print(f'{x} <= {y}: {x <= y}')
print(f'{x} >= {y}: {x >= y}') # greater than or equals to
print(f'{x} == {y}: {x == y}')
print(f'{x} == {z}: {x == z}') # 
print(f'{x} != {y}: {x != y}') # not equal to

Output ; 

values of x, y, z are 10, 11 and 11 respectivly
10 < 11: True
10 > 11: False
10 <= 11: True
10 >= 11: False
10 == 11: False
10 == 11: False
10 != 11: True

Logical operators

[and, or, not]

  • logical comparission operators works on boolean values, and the output is also boolean

Ex ; 

x, y, z = True, False, True
print(f'values of x, y, z are {x}, {y} and {z} respectivly')

print(f'{x} and {y}: {x and y}')
print(f'{x} and {z}: {x and z}')
print(f'{x} or {y}: {x or y}')
print(f'{x} or {z}: {x or z}')
print(f'not {x} : {not x}')
print(f'not {y} : {not y}')

Output ;

values of x, y, z are True, False and True respectivly
True and False: False
True and True: True
True or False: True
True or True: True
not True : False
not False : True

Identity operator

is

  • identity operator is checks if the values and as well the location of these values are same
  • output of an identity operator is a boolean

Ex ; 

a = 5
b = 5

m = 'hi'
n = 'hi'

p = q = [1,2,3] 

x = [4,5,6]
y = [4,5,6]

# comparing a and b using '==' and checking their identity
print(a == b)
print(a is b)
print()

# comparing m and n using '==', and checking their identity
print(m == n)
print(m is n)
print()

# comparing p and q using '==', and checking their identity
print(p == q)
print(p is q)
print()

# comparing x and y using '==', and checking their identity
print(x == y)
print(x is y)
print()

Output ; 

True
True

True
True

True
True

True
False

Membership operators

[in, not in]

  • Membership operators in and not in are used to check wether a value/variable is a part of an iterator,link text

Ex ;

x, y = 'o', 1
a = 'innomatics'
b = [1,2,3]
c = ('x', 5.5, 'hello')

print(x in a)
print(y in b)
print()

print(x in c)
print(y in c)
print()

print(x not in c)
print(y not in c)
print()

print(x in c[2])

Output;

True
True

False
False

True
True

True

Bitwise operators

  • bitwise operators can be used on only integers
  • bitwise operators work on bit levels
  • the given values will be converted into binary and then these operations are performed on their respective bits

Ex '; 

print(5 & 3, 'bitwise and operation (&)') 
print(5 | 3, 'bitwise or operation (|)') #
print(5 ^ 3, 'bitwise xor operation (^)') # (1,0) --->, 1 and for rest it is 0
print(~5, 'bitwise not operation (~)') # ~x ==> -(x+1)
print(12 << 1, ' bitwise left shift (<<)')
print(8 >> 1, ' bitwise right shift (>>)')

Output ;

1 bitwise and operation (&)
7 bitwise or operation (|)
6 bitwise xor operation (^)
-6 bitwise not operation (~)
24  bitwise left shift (<<)
4  bitwise right shift (>>)

Assignment operators


Ex ;

x = 12

x+=2
print(x)

x-=2
print(x)

x*=2
print(x)

x**=2
print(x)

x//=2
print(x)

x%=5
print(x)

x/=2
print(x)

# re-assigning x value 
x = 17

x&=17
print(x)

x|=5
print(x)

x^=5
print(x)

x<<=5
print(x)

x>>=5
print(x)

Output ;

14
12
24
576
288
3
1.5
17
21
16
512
16

mutable vs immutable


Ex ; 

x = 5
print(x, id(x))
x = 10
print(x, id(x))

Output ;

5 11531040
10 11531200


x = [1,2,3]
print(x, id(x))
x.append(4)
print(x, id(x))

[1, 2, 3] 140638009668288
[1, 2, 3, 4] 140638009668288

Comments

Popular posts from this blog

Navigating the GenAI Frontier: Transformers, GPT, and the Path to Accelerated Innovation ( LLM )

  Historical Context: Seq2Seq Paper and NMT by Joint Learning to Align & Translate Paper : * Seq2Seq model introduced in "Sequence to Sequence Learning with Neural Networks" paper by Sutskever et al., revolutionized NLP with end-to-end learning. For example, translating "Bonjour" to "Hello" without handcrafted features. * NMT by "Joint Learning to Align and Translate" (Luong et al.) improved Seq2Seq with attention mechanisms. For instance, aligning "Bonjour" and "Hello" more accurately based on context. Introduction to Transformers (Paper: Attention is all you need) : * Transformers introduced in "Attention is All You Need" paper. * Replaced RNN-based models with attention mechanisms, making them highly parallelizable and efficient. Why transformers : * Transformers capture long-range dependencies effectively. * They use self-attention to process tokens in parallel and capture global context efficiently.   ...

Language Modeling ( LLM )

Language Modeling ( LLM ) *   What is Language Modeling :   Language modeling powers modern NLP by predicting words based on context, using statistical analysis of vast text data. It's essential for tasks like word prediction and speech development, driving innovation in understanding human language. Types of language models :  N-gram Models  : These models predict the next word based on the preceding n-1 words, where n is the order of the model. For example, a trigram model (n=3) predicts the next word using the two preceding words. N-gram Language Model Example : Consider a simple corpus of text: I love hiking in the mountains. The mountains are beautiful. Trigram Model: P("in" | "hiking", "love") = Count("hiking love in") / Count("hiking love") P("are" | "mountains", "the") = Count("mountains the are") / Count("mountains the") Neural Language Models: Neural network-based language...

Python String.

  Innomatics Research Labs  Im a innomatics student, this is for innomatics research labs notes (the best institute of hyderabad) once search in google, course = data science and full stack development Innomatics Research Labs  is a pioneer in  “Transforming Career and Lives”  of individuals in the Digital Space by catering advanced training on  IBM Certified Data Science , Python, IBM Certified Predictive Analytics Modeler, Machine Learning, Artificial Intelligence (AI),  Full-stack web development , Amazon Web Services (AWS), DevOps, Microsoft Azure, Big data Analytics,   Digital Marketing , and Career Launching program   for students  who are willing to showcase their skills in the competitive job market with valuable credentials, and also can complete courses with a certificate. Strings: strings are a sequence or a char, enclosed in qoutes. creating a string a string can be created by  encloing a char or sequence of chars  ...