[go: up one dir, main page]

0% found this document useful (0 votes)
6 views25 pages

12 TH Python

Uploaded by

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

12 TH Python

Uploaded by

pgcriteria2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

PYTHON

PYTHON
• Python is a popular programming language. It was created by Guido
van Rossum, and released in 1991.
It is used for:

• web development (server-side),


• software development,
• mathematics,
• system scripting.
What can Python do?
• Python can be used on a server to create web applications.
• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read and modify
files.
• Python can be used to handle big data and perform complex
mathematics.
• Python can be used for rapid prototyping, or for production-ready
software development.
Why Python?
• Python works on different platforms (Windows, Mac, Linux, Raspberry
Pi, etc).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can be
very quick.
• Python can be treated in a procedural way, an object-oriented way or
a functional way.
Python Comments

• Comments can be used to


explain Python code.

• Comments can be used to make


the code more readable.

• Comments can be used to


prevent execution when testing
code.
Variables
• Variables are containers for
storing data values.
Casting
• If you want to specify the data type of a variable, this can be
done with casting.
What is a correct way to declare a
Python variable?

• var x = 5
• #x = 5
• $x = 5
• x=5
A variable can have a short name (like x and y) or a
more descriptive name (age, carname,
total_volume).

• A variable name must start with a letter or the underscore


character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three
different variables)
• A variable name cannot be any of the Python keywords.
Tokens
• A token is the smallest individual unit in a python program. All
statements and instructions in a program are built with tokens.
1. Keywords:
• Keywords are words that have some special meaning or significance
in a programming language. They can’t be used as variable names,
function names, or any other random purpose. They are used for their
special features. In Python we have 33 keywords some of them are:
try, False, True, class, break, continue, and, as, assert, while,
for, in, raise, except, or, not, if, elif, print, import, etc.
Identifiers
• Just as identity refers to a characteristic that distinguishes a person, the same principle is a
python identifier, a token in python. In Python, an identifier is a name given to a Class, Function,
or Variable. It aids in distinguishing one entity from others.

• Characteristics of Python Identifier

• The initial letter of the identifier should be any letter or underscore (_).
• Upper and lower case letters have distinct characteristics.
• Except for the initial letter, any digit from 0 to 9 can be part of the identification.
• It shouldn’t be used as a keyword
• Except for the underscore (_), an identifier cannot contain any special characters.
• Identifiers can be as long as you want them to be.
• Case matters when it comes to identifier names. Myself and myself, for example, are not the
same thing.
Operators
• Operators are tokens that, when applied to variables and other
objects in an expression, cause a computation or action to occur.
Operands are the variables and objects to which the computation is
applied. There are 7 different operators.
i)Arithmetic Operators
• It performs all the mathematical calculations. Here are a few of them:

• ( + ) Operands on either right and left sides of the operator are added.
• ( – ) Subtract the right-hand operand from the left-hand operand with
the subtraction operator.
• (✖️) operator – Multiplies both sides of the operator’s operands.
• (➗) the left-hand operand by the right-hand operand with the division
operator.
• (%) a percentage divides the left-hand operand by the right-hand
operand and returns the remainder with the modulus operator.
ii) Relational Operators
• A relational operator is a type of operator that examines the
relationship between two operands. Some of the relational operators
are:

• (== ) Check if two operands’ values are equal.


• (!= )Check if two operands’ values are not equal.
• (>) Check if two operands’ values are not identical (same as the!=
operator).
iii) Assignment Operators
• The assignment operators are employed to allocate a value to a
variable. A few examples are:

• (+=)It adds the right side input to the left side input and then assigns
the result to the left side input.
• (-= )Augmented assignment operator- It takes the right side operand
and subtracts it from the left side operand, then assigns the result to
the left side operand.
iv) Logical Operators
• The logical operators compare two boolean expressions and yield a
boolean result. Like

• The logical AND operator makes a condition true if both operands are
true or non-zero.
• The logical OR operator returns true if one of the two operands is true
or non-zero.
v) Bitwise Operators
• The bitwise operator manipulates individual bits in one or more bit
patterns or binary numbers. For example, If a binary XOR operator (^)
is set in one input value but not both, it copies the matching binary 1
to the result.
vi) Membership Operators
• The membership operator checks for membership in successions,
such as a string, list, or tuple. Like in a membership operator that
fetches a variable and if the variable is found in the supplied
sequence, evaluate to true; otherwise, evaluate to false.
vii) Identity Operators
• When comparing the memory locations of two objects, identity
operators are used. If two variables point to separate objects, it does
not return true; otherwise, it returns false.
4. Literals
• Literals, tokens in Python, are data elements with a fixed value. Literals return a
value for an object of the specified type. Python supports a variety of literals:
• String Literals
• Numeric Literals. These are further of three types, integer, float, and complex literals.
• Boolean Literals
• Literal Collection
• Lists, tuples, dictionaries, and sets are all examples of literal collections in Python.
• A list is a collection of elements enclosed in square brackets and separated by
commas. These variables can be of any data type, and their values can be altered.
• Tuple: A comma-separated list of elements or values in round brackets is also known
as a tuple. Values can be of any data type, but they cannot be modified.
• Dictionary: It’s an unsorted collection of key-value pairs.
• The “set” is an unordered collection of objects enclosed in curly braces.
5. Punctuators(delimeters)
• Punctuators are tokens in python employed to put the grammar and
structure of syntax into practice. Punctuators are symbols that are
used to structure programming sentences in a computer language.
Some commonly used punctuators are: ‘, ‘ ,#, \ ,( ) ,{ },[ ] ,@ ,: , =

You might also like