0% found this document useful (0 votes)
2 views13 pages

Python Programing

The document provides an overview of programming concepts, focusing on variables, data types, literals, operators, control statements, loops, and strings. It explains the use of numeric data types, boolean and complex numbers, as well as base and type conversion. Additionally, it covers string manipulation techniques such as indexing and slicing, along with examples of basic loop operations.

Uploaded by

lenkarakesh2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views13 pages

Python Programing

The document provides an overview of programming concepts, focusing on variables, data types, literals, operators, control statements, loops, and strings. It explains the use of numeric data types, boolean and complex numbers, as well as base and type conversion. Additionally, it covers string manipulation techniques such as indexing and slicing, along with examples of basic loop operations.

Uploaded by

lenkarakesh2005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BY ABDUL BARI SIR

EDITOR: LENKA RAKESH


ALL THE BEST
VARIBLES

✓ A variable is used to store a value and also gives a name to that value. We can
retrieve and update the value which means data.
✓ Note: After update the value of the variable (ID) of the variable different as compare
before the update the value. (Variables is also called Operands
✓ Actually, variable create the new memory allocation for updated value
✓ Variable can be declared without value.
✓ Declaration and installation performed simultaneously

DATA TYPES

Numeric data types (int & float)


A Numeric data type is a data type that represents numbers and allows mathematical
operations on them. ( either negative nor positive numbers)
int is a integer data type
Float datatype
✓ A float is a numerical data-type which is represented in the decimal formate
✓ Floating point represntaion as a= 125E 2(O/P: 12500.0) B=125E-2(O/P : 1.25)
✓ A=20 where (A is mentissa 20 is a exponent)
✓ Allows both negative and positive values.

Numeric types (Boolean and Complex)


BOOLEAN
Bool: A bool numeric data type which gives true and false based on
the condition.
✓ True (1) and False(0)
✓ First letter of True and False must be capital
✓ Type is used know the type of the function.
COMPLEX
Complex: A number which can be represent in a+bj formate is called
Complex number.

LITERALS
Literal: A direct values that are used in a progrm is called as literals.
✓ We can sperate large numbers by underscore(_)
✓ A=125_(syntax error :invalid decimal literal)
✓ B=_456(Syntax error :invalid decimal literal )
✓ C=456_125(right)
✓ why error means python treating as vriable name not a literals
we start variable by underscore also . so it is genrate syntax
error
✓ undersore are use only for readability

INTEGER LITERAL --- NUMBER SYSTEM

NUMBER SYSTEM
1. Decimal
2. Binary
3. Octal
4. Hexa Decimal
Decimal = {0,1,2,3,4,5,6,7,8,9}
Binary = {0,1}
Octal = {0,1,2,3,4,5,6,7}
Hexa={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} { A to F are 10 to 15}
Follow the (conversion method)
A can be written as dec ,bin, oct, hexa but answer is 10 only like we are calling the value 10
in different languages ( ten, పది, பத்து, പത്ത്)

BASE CONVERSION

Base conversion: A base-conversion is process of converting one-base number to another


base-number
Example: bin to oct, hex to dec, oct to bin etc.

TYPE CONVERSION

Type conversion: A type conversion is process of converting one data type to another data
type by type keyword

OPERATORS
✓ Arithmetic operators
✓ Expressions
✓ Operator precedence
EXPRESSIONS

✓ EXPRESSIONS: Expression is combination of operands and operators is called


expressions
a=20
b=30 # (=) is assignment operator
c=a+b # (c) is operand (+) is operator
print(c) # print(c) is a result of an expression

OPERATOR PRECEDENCES (EXPRESSIONS)


BITWISE OPERATOR

AND (&) OPERATOREXAPMPLES

1*1=1
1*0=0
0*1=0
0*0=0
OR OPERATOR
1+1=1
1+0=1
0+1=1
0+0=0

Notation we used for or is (|)

XOR (^) OPERATOR


1^1=0
1^0=1
0^1=1
0^0=0
0 doesn’t
Have value
So ignore 0
On starting position

BITWISE LEFT SHIFT (<<)


insert the
extra 0
in the empty
place after
moving the
digits
from left
side
BITWISE RIGHT SHIFT (>>)
We cannot insert the 0 in the empty place. number must and should
move right side
(remove the first
digit from right
hand side return
Remaining digit)
Float is not
consider so it is
integer
>> means ½ of the
Number

CONTROL STATEMENT

✓ if
✓ else
✓ elif
CHAINING COMPARISON
LOOPES AND CONTROL FLOW
✓ While loop
✓ For loop
✓ Continue, break, pass
✓ Infinite loop
✓ Match case
Note : looping statements required more practice
An infinite loop in Python is a loop that never terminates on its own because the condition
controlling the loop always evaluates to True. These loops keep running until you manually
stop them (e.g., pressing Ctrl + C in the terminal)
A. Basic Loop Questions (1–10)
1. Print numbers from 1 to 10.
2. Print all even numbers from 1 to 50.
3. Print all odd numbers from 1 to 50.
4. Print the sum of first 50 natural numbers.
5. Print the multiplication table of a given number.
6. Count the digits in a given number.
7. Reverse a given number using a loop.
8. Find the factorial of a given number.
9. Check whether a given number is a prime number.
STRINGS

✓ A String is collection of homogenous elements such as numbers, alphabets, special


symbols, (space) that are written in between codes.

TRAVESING
• Traversing is a process of travelling on the string
• We can access the string by two methods
method:1
S1= “hello”
For I in range(s1):
Print(i)
Method: 2
For I in range(len(s1)
Print(s1[i])

STRING LITERALS

INDEXING AND SLICING


✓ String indexing
✓ Immutable string
✓ String Slicing
STRING INDEXING
➢ String has a immutable character
➢ If we modified a string it always gives new string
➢ It have both negative and positive index values

STRING SLICING
➢ Slicing is process of accessing the subset of elements from sequence like lists , tuple
,sting etc

➢ Syntax : string-name[start: stop: step]

# String slicing

s = "Hello, World!"

print(s[0:5]) # 'Hello' -> from index 0 to 4

print(s[7:12]) # 'World' -> from index 7 to 11

print(s[:5]) # 'Hello' -> start is 0 by default

print(s[7:]) # 'World!' -> goes till the end

print(s[::2]) # 'Hlo ol!' -> every 2nd character

print(s[::-1]) # '!dlroW ,olleH' -> reverse string

# List slicing

numbers = [10, 20, 30, 40, 50]

print(numbers[1:4]) # [20, 30, 40]

print(numbers[:3]) # [10, 20, 30]

\print(numbers[::2]) # [10, 30, 50]

You might also like