Class 11 Chapter 3 Python Fundamentals
Class 11 Chapter 3 Python Fundamentals
3: Python
Fundamentals
You’ll be learning about Python’s Basic
like
• Character set,
• Tokens,
• Expressions,
• Statements,
• simple input and output
Character Set
• Character set is a set of valid character that a language can
recognize.
• Represent
• any letters A-Z, a-z
• digit or symbols. 0=9
• Special symbols +_*/(){}[]=!% _
Tokens
• In a passage of text, individual words and punctuation marks
are called Tokens.
• Another words we can say Lexical units.
Python has following Tokens:
• Keywords
• Identifiers
• Literals
• Operators
• punctuations
1. keywords
• Keywords are the words that convey a special meaning to the
language interpreter.
• Contain following keywords:
• False, in, is, or, pass, while, for, not, try etc…
2. Identifiers
• Identifiers are fundamentals building blocks of a program and
are used as the general terminology for the names given to
different parts of a program
• Variables, object, classes, functions, lists, dictionaries etc…
Following are some valid identifiers
• Myfile,
• date123,
• _as,
• aSDF234
Following are some invalid identifiers
• DATE-IS
• 25th
• Break
• My.myname
3. Literals / values
• Literals are data items that have a fixed value.
• we can say as a constant value.
Several kinds of Literals
• String literals
• Numeric literals
• Boolean literals
• Special literal None
String Literals
• A string literals is a sequence of characters surrounded by
quotes.
• There are two types of string literals
• Single-line
• multiline
• Ex:
• a=“Alchemy
• Surat”
• Print(a)
• o\p: Error
• A=“Alchemy\
• Surat”
• Print(a)
• o\p: 4 o\p: -4
Binary Operator
• Arithmetic +,-,*,/
• Bitwise & , ^ , |
• Shift >>,<<
• Identity is, is not
• Relational >,<,<=,>=,!=
• Assignment =,+=, *=,-=
• Logical And, Or
• Membership in, not in
Punctuator
• Punctuator are symbols that are used in programming
languages to organize sentence structures.
• Ex: ‘ “ \ () [] {} @ , : . ; ` =
Barebones of a Python Program
Various components like:
• Expressions
• Statements
• Comments
• Function
• Block and indentation
Expressions:
• Any expressions is any legal combination of symbols that
represents a value.
• Ex: 25, x + 10, c>6 etc..
Statements:
• a=5 correct
• 5=a incorrect
Variable Definition
• A variable is created when you first assign a value to it.
• X=10
• Print(X)
Dynamic typing:
• A variable is defined by assigning to it some value.
• A=10
• Print(A)
• A=15
• Print(A)
Type()
• A=10
• Type(A)
• <class int>
Simple input and output:
• To get input from user interactively, you can use built in function
input().
• Ex:
• a=input(“what is your name?”)
• print(a)
• o\p:
What is your name? Jignesh
jignesh
• The input() function always returns a value of string type.
• Type(a)
• o\p: str
• Ex:
• o\p:
• Enter any number: 5
• type(b)
• o\p: str
Reading numbers:
• String values cannot be used for arithmetic or other numeric
operations.
• You need to have values of numeric types int or float.
• Python offers two functions: int() and float() to be used with input() to
convert the values received through input() into int and float types.
values:
• a= int(input(“Enter any number:”))
• Print(a)
• o\p: error
• a= float(input(“Enter any number:”))
• Print(a)
• o\p: error
Features of print statements
• It auto-converts the items to strings.
• It inserts spaces between items automatically because the
default value of sep argument is space(‘’).
Ex: print(“my”, “name”, “is”)
o\p: my name is