0% found this document useful (0 votes)
25 views

XI IP Python Fundamentals

Uploaded by

Roshan Das
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)
25 views

XI IP Python Fundamentals

Uploaded by

Roshan Das
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
You are on page 1/ 8

BIRLA PUBLIC SCHOOL, DOHA-QATAR

INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI

INTRODUCTION
Computer actions are governed by the IPO cycle. A program is a
set of instructions that govern the processing.

Character set: a set of valid characters that a language can recognize.It


represents any letter or digit or any other symbol.It supports unicode
encoding standard.

Letters:A to Z , a to z
Digits:0 to 9
Special symbols:*, < ,@, _ etc
White spaces :tab,newline
Other charcaters :can process all ASCII and Unicode characters as apart of
data or literals

Tokens (lexical unit)are the smallest individual unit in a program.

● Keywords
● Identifiers
● Literals
● Punctuators
● Operators

● Keywords are reserved words that convey a special meaning


● Identifiers are building blocks of a program
Rules :
❖ Long sequence of letters and digits

❖ First character must be a letter ,underscore (_)

❖ Case sensitive

❖ Digits 0 to 9 can be a part of the identifier except the first letter

❖ Unlimited in length

❖ Must not be a keyword

❖ Cannot contain special character except _


For eg:
BIRLA PUBLIC SCHOOL, DOHA-QATAR
INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI
_hello
Grade1
Basic_pay

● Literals are data items that have a fixed data value

String literals: ‘hello’, ”hello”

Python allows non graphic characters- those characters that cannot be typed
directly from the keyboard. (\t,\n)

For example ,For a new line type


print(‘hello \neveryone’)
hello
everyone

String types in python

Single line strings


For eg:
print('hello')
print('world')
Output
hello
world

Multiline strings

For eg:
Text='hello\
world'
print(Text)
Output
helloworld
BIRLA PUBLIC SCHOOL, DOHA-QATAR
INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI

For eg:

print('''hello
everyone ''')

Output
hello
everyone

for eg:
print("""hello
everyone
""")

Output
hello
everyone

Size of strings

‘abc’ :size is 3
Ash\’s birthday : size is 14

For eg:

text="Ash\'s birthday"
print(len(text))

Output

14

len(objectname ) gives the size of the string

Integer literals: 10
BIRLA PUBLIC SCHOOL, DOHA-QATAR
INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI
Floating point literals:12.5
Boolean literal:True or False
Special Literal:None
It indicates the absence of a value

● Punctuators : are symbols that are used in programming language to


organise programming.
[],{},(), . , ;

● Operators are tokens that triggers some computation or action when


applied to variables or other objects in an expression.

Unary :one operand


+Unary plus( number itself )
-Unary minus(negation of the number)
For example:
a=5
print(+a)
a=15
print(-a)

Output

5
-15

Binary:two operands

Arithmetic Operators
a+b
a-b
a*b
a/b
a%b
a//b(floor division( divides and discards the fractional part )
BIRLA PUBLIC SCHOOL, DOHA-QATAR
INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI

Relational <,<=,>,>=,!=

Assignment or shorthand operators


(=,+=,-=,*=,/=,**=,//=,%=,**=)

a+=10
a-=10
a*=10
a/=10
a%=10
a//=10
a**=10

Logical operators
Logical AND
Logical OR

Identity operator(is , is not)


For eg:

a=10
b=15
if a is b:
print("yes")
else:
print("no")

Membership operator(in, not in)

For eg:
a=[10,20,30]
if 30 not in a:
print("yes")
else:
print("no")
BIRLA PUBLIC SCHOOL, DOHA-QATAR
INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI
Barebones of a program

⮚ Comments are non executable additional information added in a


program for readability.
Comments enclosed in triple quotes or triple apostrophe are called
docstrings

Single line
'''
Text here
'''
Mutiline

"""
Text here
"""
⮚ Function is a code that has a name and that it can be reused (executed
again ) by specifying its name in the program where needed

def add(a,b):
c=a+b
print(c)

a=6
b=2
add(a,b)

⮚ Expressions:any legal combination of symbols that represent a value


Eg:12.5
a+b

⮚ Statements are programming instructions that does something .ie


some action take place

For eg:
Sum=a+b
BIRLA PUBLIC SCHOOL, DOHA-QATAR
INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI

⮚ Blocks and indentations :a group of statements which are part of


another statement or a function are called block or code –block or
suite in python

Variables and assignments:named labels whose values can be used and


processed during program run.

Creating a variable

Marks=70
Name=’Jake’

Multiple assignments

For eg:

a,b,c=10,4,5
print(a,b,c)

Output:

10 4 5

Dynamic typing:
A variable pointing to a value of a certain type can be made point to a value /
object of different type.
For eg:
a=10
print(type(a))
print(id(a))
a="hello"
print(type(a))
print(id(a))

Simple Input and Output


BIRLA PUBLIC SCHOOL, DOHA-QATAR
INFORMATICS PRACTICES
PYTHON FUNDAMENTALS
GRADE: XI
input( ) always returns a value of string type

syntax:

<variablename>=int(input(<prompt string>))

Reading numbers
print () – without any value or name or expression prints a blank line

Example

# print the sum of two numbers


a=int(input("Enter a value for a"))
b=int(input("Enter a value for b"))
sum=a+b
print(" The sum of a and b is ",sum)

Output

Enter a value for a10


Enter a value for b20
The sum of a and b is 30

You might also like