Python Notes for B-Tech , Bsc , Bca....

 

UNIT-1

What is Python?

* Python is a high level , general purpose object oriented programming language.

* It was created by Guido Van Rossum in 1991 at CWI in Netherland.

Syntex-

print("Hello")

-----------------------

Features of Python:-

* Simple and easy to learn

* Open source

* Platform independent

* Rich Library

* Portable

* Interpreted

-----------------------

Applications of  Python :-

* Web development

* Game development

* IOT development

* AI

* Machine Learning

-------------------------------

# Input / Output :- 

* For taking input in python , we have input()

 For taking output in python , we have print()

------------------------------

Python Comments :- Comments are nothing but ignorable part of python program that are ignored by the interpreter.

There are 2 types of Comments -

1. Single line comment

syntex- #..........

2. Multi line comment

syntex- ''' ..........

..........

........

'''

-----------------

Keywords:- Keywords are the words whose meaning is already being defined in Python interpreter.

* Python keywords are Case sensitive.

* We cant use a keywords as a variable name, method name or any other identifiers.

* Total 33 keywords in Python.

------------------------

Data Type:- Data Type represent the different kinds of values that we stored on the variable.

* Basic data type in python:-

1. Number

2. String

3. dict

4. set

5. List

6. tuple

* We do not need to specify the data type explicitly , based on value types allocated automatically.

--------------------------

Variable :- Variable is the name of memory location where we can store different type of values.

-------------------------

Python Interpreter:- A python interpreter is a computer program that convert each high-level program statement into machine code.

-----------------------

Python Shell:- The python shell is the interpreter that executes your Python program , other piece of Python code or simple commands.

It is also used to execute a single Python commands and display the result.

----------------------

Python Identation:- It refers to adding white space before a statement to a particular block of code. In another words a, all the statement with the same space to the right , belong to the same code block.



----------------------

Literals:- Literals are constant values assigned to constant variable. It represent fixed values that cannot be modified.

* We mainly have five types of literals which includes string literals, numeric literals, boolean literals, literal collections and a special literal None.

---------------------------

Python Operators:- They are used to perform operations on values and variable.

Types :-

1) Arithmetic Operator- They are used to perform operations on values and variables.

example :  + , - , *  , /

2) Logical Operator- They perform LogicalAnd , LogicalOr and LogicalNot operations. They are used to combine conditional statement. 

example : OR , NOT , AND.

3) Bitwise Operator- They act on bits and perform the bit-by-bit operations. They are used to operate on binary number.

example: & , >> , << , | etc .

4) Assignment Operator- They are used to assign values.

example: = , += , -= , etc.

5) Relational Operator- They are used to compare the operand values. 

example: == , > , < , etc

6) Ternary Operator- It allows us to evaluate if a condition is true or false.

example: if , else .

-----------------------------

UNIT-2

Flow Control:- Flow Control describe the order in which statement will be executed at runtime.

1. Conditional Statement-

 👉 if statement -

syntex - if condition :

statement

👉 if else - 

syntex- if condition:

statement

else:

statement

👉else if

syntex- if condition:

statement

elif condition:

statement

else:

statement

-----------------------------

Example of else if ::

age = int (input ("Enter your age: "))

if age<18 :  

    print('You are too young to marry')

elif age>60:

    print('You are too old to marry')

else:

    print("we will find a perfect match for you")


output ~

Enter your age: 25

We will find a perfect match for you

--------------------------------------------------

2. Iterative statement-

👉 for loop

syntex- for var-name in range(start,end):

statement

Example of for loop:-

table = int(input("Enter a number : "))

for number in range(1,11):

      print(table * number)

output~

Enter a number : 6

6     12    18    24    30    36    42    48    54    60

-------------------------

👉 while loop

syntex- while condition:

statement

    Example of while loop-

password = "vaibhav"

input_password = input ("enter password :")

while password != input_password:

            input_password = input("enter password :")

else :

       print("unloacked !! ")

output~ 

Enter password :vaibhav

unlocked !!

--------------------

3. Loop control statement -

👉Continue statement

example- 

for num in range(1,11):

    if num % 2 == 0 :

        continue

   else:

        print(num)

output~

1     3     5     7     9

👉break statement

example - 

for num in range(1,11) :

    if num % 2 == 0:

        break

   else:

        print(num)

output~

1       

 👉pass: The pass statement is used as a placeholder for future code. When the pass statement is executed , nothing happen but you avoid getting an error when empty code is not allowed.

-----------------------

UNIT-3

List:- List is a data structure which is also called collection of items, in which we can store anything like-string, float , integer.

syntex-              list-name=[item1 , item2, ......... , item n ]

Note- * We write the item of the list inside "square brackets" ([]) and each item is seperated by "commas" (,).

* Duplicate are allowed.

* Mutable in nature.

-------------

Program to print using indexing :-

list1 = [10, 'vaibhav' , true , 10.5 ,  'bhatnagar' ,  10]

print(list1[2])

output~      [true]

------------------------

Program to print by slicing :-

list2 = [10 , 'vaibhav' , true , 10.5 , 10]

print( list2[1:4] )

output~   [ 'vaibhav' , true , 10.5]

----------------------

Count method () : Count () is a Python in-built function that returns the number of times an object appears in a list.

Example-  

list2=[10 , 'vaibhav' , true , 10.5 , 10]

print(list2.count(10))

output: 2

--------------------

index method () : It return the position at the first occurence of the specified value.

Example- list2 = [10 , 'vab' 20 , 13.5 , 30 ]

print(list2.index(30))

output- 4

-----------------------

insert method () : It insert the specified value at the specified position.

Example- 

list3= [10 , 'vab' , 30 , 40.5]

list3.insert(3 , "Hello")

print(list3)

output- [10 , 'vab' , 30 , 'Hello' , 40.5]

-----------------------

pop method () : It is used to delete the element from the specified position.

Example- 

list4= [10 , 'vab' , 30]

list4.pop(2)

print(list4)

output- [10 , 'vab']

* IF WE DOES NOT GIVE INDEX POSITION THAN BY DEFAULT IT WILL DELETE LAST ELEMENT

----------------------

Python Tuple:- It is a data structure which is also called Collection of items , in which we can store anything like string , float , integers.

Syntex: tuple-name=(item 1 , item 2 , ..... item n)

Note- * We write the item of the tuple inside parathesis "()" and each item is seperated by comma ",".

* Duplicates are allowed.

* Immutable in Nature.

-------------------------

Set:- Set is a data structure which is also called collection of items in which we can represent a group of unique value as a single entity.

Syntex: set-name={item 1 , item 2 , .......item n }

* We write the item of set inside the curly braces "{}" .

* Insertion order is not preserved.

* Indexing and slicing not safe.

* Hetrogenous element are allowed.

* Mutable in Nature.

--------------------

Dictionary:- Dictionary is a data structure in which we represent a group of object as key-value pair.

syntex: dict_name = {"key": "value"}

Note-

* Insertion order is preserved.

* Indexing and slicing not work.

* Hetrogenous element are allowed.

* Mutable in nature.

* Key must be unique , but duplicates value are allowed.

Create Empty Dict:- 

var=dict()

print(type(var))

or

var = {}

print(type(var))

------------------

Comments

  1. Learning R programming can be challenging, especially when dealing with data analysis, visualization, and statistical modeling tasks. A reliable r programming assignment writing can provide valuable guidance in understanding coding concepts, debugging errors, and applying analytical techniques effectively. Such support helps students strengthen their programming skills while completing assignments with greater accuracy. For those struggling with complex R projects, expert assistance can make learning more manageable and contribute to better academic performance in data science and statistics courses.

    ReplyDelete

Post a Comment

Popular posts from this blog

Software Engineering Full Notes... B-Tech (C.S.) , Bsc (CS) , BCA....

Data Mining Assignment

Important Question Of Software Engineering....