2.fundamentals of Python
2.fundamentals of Python
CONCEPTS
IN PYTHON
•Character set defines the valid characters that can be used in a
source program .Python uses the character set as the building block
to form the basic program elements such as variables, identifiers
,constants, expressions etc.
•Python uses the traditional ASCII character set. The latest version also
CHARACTER SET recognizes the Unicode character set.
•The ASCII character set is a subset of the Unicode character set. The
main limitation of ASCII character is its inability to represent more
than 256(=28).
•Unicode character set, a set that use 2 bytes (16 bits) per character..
❑Identifier is the name given to entities like class, functions, variables
etc. in Python. It helps differentiating one entity from another.
❑Rules for writing identifiers:
▪Identifiers can be a combination of letters in lowercase (a to z) or
uppercase (A to Z) or digits (0 to 9) or an underscore (_).
▪ Names like my Class, var_1 and print_this_to_screen, all are
valid example.
Keywords are the reserved words None continue for lambda try
in Python. Keywords cannot be
used as variable name, function True def from nonlocal while
name or any other identifier. They
are used to define the syntax and
structure of the Python language. In and del global not with
Python, keywords are case
sensitive. as elif if or yield
There are 33 keywords in Python.
assert else import pass
All the keywords except True, False
and None are in lowercase and
they must be written as it is. break except in raise
VARIABLES • We need not to declare explicitly variable in Python as
we do in c, c++, and java.
Variables are used to reference
values that may be changed in the int a, b;
program. float c, d;
When we assign any value to the variable that variable is
Variable is a name of the memory declared automatically. The statement for assigning a
location where data is stored. Once value to a variable is called an assignment statement. In
a variable is stored that means a Python, the equal sign (=) is used as the assignment
space is allocated in memory.
operator. The syntax for assignment statements is as
follows:
Variable = expression
DATA TYPE There are various data types in Python. Some of the important
types are listed below.
A data type is a set of values, and Numbers
a set of operators that may be Integers, floating point numbers and complex numbers falls
applied to those values. under Python numbers category. They are defined as int, float
For example, the integer data and complex class in Python.
type consists of the set of integers, a) Integer (signed) -Numbers (can be both positive and
and operators for addition, negative) with no fractional part.e.g. 100
subtraction, multiplication, and b) Float pointing - Real numbers with both integer and
division, among others. Integers, fractional part e.g. 100.90
floats, complex numbers and strings c) Complex - In the form of a+bj where a forms the real part
are part of a set of predefined and b forms the imaginary part of complex number. e.g. 3+4j
data types in Python called the
built-in types. Strings
String is sequence of Unicode characters. We can use single
quotes or double quotes to represent strings.
s = "This is a string"
EXPRESSION y=1 # Assign 1 to variable y
y=x+2
print(y)
INPUT STATEMENT
125
PRACTICE QUESTION 2 a) Keywords are reserved words that are used to
construct instructions.
b) Keywords are used to calculate mathematical
What are keywords operations.
c) Keywords are used to print messages like "Hello
in Python? World!" to the screen.
d) Keywords are the words that we need to memorize to
program in Python.