Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views7 pages

Grade 10 Python Notes

Uploaded by

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

Grade 10 Python Notes

Uploaded by

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

ABU DHABI INDIAN SCHOOL – BRANCH 1, AL WATHBA

GRADE-10 -COMPUTER SCIENCE-PYTHON NOTES

Introduction:-Python was created by Guido van Rossum in 1991 and further developed by the Python
Software Foundation. It was designed with a focus on code readability, and its syntax allows us to express
concepts in fewer lines of code.

Features of Python
 Easy to learn
 Platform independent
 Easy to learn syntax
 Free to use and easily available
 Case sensitive
 An interpreted language

Application of Python Programming


 1. Web Development
 2. Machine Learning and Artificial Intelligence
 3. Data Science
 4. Game Development
 5. Audio and Visual Applications
 6. Software Development
 7. CAD Applications
 8. Business Applications
 9. Desktop GUI
 10. Web Scraping Application
Applications that are coded in Python include popular ones like Netflix, Spotify, and YouTube.

Programming in Python
Python allows you to work in two modes.
 Shell mode/Interactive mode
 Script mode
In the interactive mode, as we enter a command and press enter, the very next step, we get the
output. The output of the code in the interactive mode is influenced by the last command we gave.
Interactive mode is very convenient for writing short programs.

A Python program can be written in a file in script mode. This file can then be saved and executed
using the command prompt. Script mode is very suitable for writing long programs. The file name
extension of a Python file is “.py”.

print () function
The print() function prints the specified message to the screen or other standard output device.
Syntax:- print(“message”/variable, sep=”separator value”, end=”end value”)
In the above syntax, sep='separator value' is optional. Specify how to separate the messages or variables if
there is more than one. The default value of the separator is ' ' (space)
end='end value' is optional; it will specify what to print at the end. The default value of end is '\n' (newline
character)

Using separators with the print() function


, - the values are displayed with a space between them.
\n - used to end a line and start a new line.
sep - String inserted between values, default, a space.
end -String appended after the last value, default, a new line.
Predict output of the following Python code:-
print("Welcome", "to", "Python")
print("Programming")
Output
Welcome to Python
Programming
program
print("Welcome", "to", "Python",sep="#",end="&&&")
print("Programming")
Output
Welcome#to#Python&&&Programming

Data types
In Python , a data type represents the type of data stored in a variable. The basic types used in Python
are:-
int (integer) –It represents integral numbers. e.g. 45,78,-56,-34.
float – It represents floating-point values. e.g. 3.14,18.0,-48.7 ,etc.
str(string) – A string type represents strings of characters enclosed within single or double quotation marks
( ‘ ‘ or” “).e.g. “Hello”, ’218’,”grade10”
bool(Boolean) –It represents logical values in the form of True or False. e.g., 45>5 evaluates to True, and
7<1 evaluates to False.

Character set
The Python character set is a valid set of characters recognized by the Python language. These are the
characters we can use while writing a script in Python. Those are,
Alphabets: All capital (A-Z) and small (a-z) alphabets.
Digits: All digits 0-9.
Special Symbols: Python supports all kinds of special symbols like” ‘ l ; : ! ~ @ # $ % ^ ` & * ( ) _ + – = { } [ ] \ .
White Spaces: White spaces like tab space, blank space, newline, and carriage return.
Other: All ASCII and UNICODE characters are supported by Python, which constitutes the Python character
set.

Keywords
Keywords are words that have some special meaning or significance in a programming language. They
can’t be used as variable names or for any other random purpose. They are used for their special
features.
Examples:- int, float, if, else,elif, etc.

Identifiers
Identifiers are the names given to any variable for its identification. Python is a case-sensitive
language, and it has some rules and regulations for naming an identifier. Here are some rules to name
an identifier:-
 As stated above, Python is case-sensitive. So, case matters in naming identifiers. And hence,
AREA and area are two different identifiers.
 Identifier starts with a capital letter (A-Z), a small letter (a-z), or an underscore( _ ). It can’t
start with any other character.
 Except for letters and underscore, digits can also be a part of an identifier, but can’t be the
first character of it.
 Any other special characters or whitespaces are strictly prohibited in an identifier.
 An identifier can’t be a keyword.
For Example, some valid identifiers are gfg, GeeksforGeeks, _geek, mega12, etc.
While-9_road, #tweet, I am, int, etc. are invalid identifiers.

Literals/Values
Literals are the fixed values or data items used in a source code. Python supports different types of
literals, such as:
i. String Literals: The text written in single, double, or triple quotes represents the string literals in
Python. For example: “Computer Science”, ‘sam’, etc.
ii. Character Literals: Character literal is also a string literal type in which the character is enclosed
in single or double quotes.
# Character Literals
a = 'G'
b = "W"
print(a)
print(b)
Output:
G
W
(iii). Numeric Literals: These are the literals written in the form of numbers. Python supports the
following numerical literals:
a). Integer Literal: Integer literals in Python represent whole numbers. They can be positive, negative,
or zero and do not contain a decimal point.
b). Float Literal: A float literal in Python represents a floating-point number, which is a number
with a decimal point.
c). Boolean Literals: Boolean literals have only two values in Python. These are True and False.

Punctuators:
These are the symbols that are used in Python to organize the structures, statements, and
expressions. Some of the Punctuators are: [ ] { } ( ) @ -= += *= //= **== = , etc.

Operators:-
Operators are used to perform operations on variables and values. Python divides the operators in the
following groups:

 Arithmetic operators
 Comparison/Decision/Selection operators
 Logical operators

Python Arithmetic Operators


Arithmetic operators are used with numeric values to perform common mathematical operations:
Let x=10 and y=5
Operator Name Example Output/Result
+ Addition x+y 15
- Subtraction x-y 5
* Multiplication x*y 50
/ Division x/y 2.0
% Modulus x%y 0
** Exponentiation x ** y 100000 (10**5)
// Floor division x // y 2

Python Comparison Operators


Comparison operators are used to compare two values:
Let x=10 and y=5
Operator Name Example Result
== Equal x == y False
!= Not equal x != y True
> Greater than x>y True
< Less than x<y False
>= Greater than or equal to x >= y True
<= Less than or equal to x <= y False

Python Logical Operators


Logical operators are used to combine conditional statements:

Operator Description Example Result


and Returns True if both statements are True 10< 5 and 10 < 10 False
or Returns True if one of the statements is True 10 < 5 or 10 > 4 True
not Reverse the result, returns False if the result is True not(10<5) True

Using input() Function


The input() function is used to accept/input/obtain the value for a variable from the user. To input
integer and float values, you can use int() or float() along with the input() function. In Python, the input()
function takes one string argument.
eg: a=int(input(“enter a number”)) - for entering a integer
name=input(“enter your name”) - for entering a string value like name

Indentation in Python
Python follows a particular style of indentation to define the code, since Python functions don’t have any
explicit beginning or end, like curly braces, to indicate the start and stop for the function; they have to rely
on this indentation.

Comments, which are used to enhance the readability and understandability of a program, are
ignored by the Python interpreter
i. Single-line comment: Which begins with a # sign.
ii. Multi-line comment (doc string): either write multiple lines beginning with # sign
or use triple-quoted multiple-line. E.g.
‘’’This is my
first
python multiline comment
‘’’

Types of Control Structures:-


Control structures are used to control the flow of execution of the program. There are three
different types of control structures in Python.
 Sequential Control Structure: Sequential control structure in Python refers to the execution of
code statements in a linear order, one after the other, from top to bottom. This is the default way
Python interprets and runs code. Each line of code is processed in the sequence it appears, without
skipping or repeating any lines.
 Conditional Control Structure: Conditional statements in Python are used to execute certain blocks
of code based on specific conditions. These statements help control the flow of a program, making
it behave differently in different situations. In Python, there are three types of conditional
structures:
 a)simple if
 b)if-else c)if-elif-else
 Iteration(Looping) Control Structure: The looping control structure executes a set of statements
repeatedly depending on the value of a condition(Boolean expression). As soon as the condition
becomes false, the control comes out of the loop. In Python , there are two types of loops:
a) for loop , b)while loop

Simple if statement
The if statement consists of a conditional expression followed by a statement or a block. The
keyword if is used to evaluate a condition. The block is executed only if the condition is True. If the
condition is False, then the statement or the block is ignored.
Syntax: w
if<condition>:
statement(s)

The if….else statement:-


Else allows us to specify a block of code that will execute if the condition(s) associated with an if or elif
statement evaluate to False. The else block provides a way to handle all other cases that don't meet the
specified conditions.
Syntax:
if<condition>:
Statement(s)
else:
Statement(s)

The if….elif….else Statements


The if-elif-else statement in Python is used to execute different blocks of code based on multiple
conditions. It allows for multi-way decision-making, where it checks multiple conditions sequentially and
executes the code block associated with the first true condition. If no conditions are true, the else block (if
present) is executed.
Syntax:
if<condition>:
Statement(s)
elif<condition>:
Statement(s)
.
.
.
else:
Statement(s)

You might also like