Python Fundamentals

Python Fundamentals

Python is a general-purpose, high level, object oriented programming language. It was created by Guido van Rossum, and released in 1991.

Some Features of Python Language are:

  1. Python is portable and platform independent.
  2. Free and Open Source
  3. Simple syntax similar to the English language.
  4. Python is an interpreted Language.
  5. Python is an object-orientated Language.
  6. Python uses indentation for blocks and nested blocks

Two modes of Python Language are:
(i) Interactive Mode: it works like a command interpreter as shell prompt works in DOS Prompt or Linux. On each (>>>) symbol we can execute one by one command.
(ii) Script Mode: it used to execute the multiple instruction (complete program) at once.

Python Character Set: Character Set is a group of letters or signs which are specific to a language. Character set includes letter, sign, number and symbol.

  • Letters: A-Z, a-z
  • Digits: 0-9
  • Special Symbols: _, +, -, *, /, (, #,@, {, } etc.
  • White Spaces: blank space, tab, carriage return, newline, form feed etc.
  • Other characters: Python can process all characters of ASCII and UNICODE.

Python Tokens: Token is the smallest unit of any programming language. It is also known as Lexical Unit. Types of token are
i. Keywords
ii. Identifiers (Names)
iii. Literals
iv. Operators
v. Punctuators

Keywords: Keywords are reserved words. Each keyword has a specific meaning to the Python interpreter. As Python is case sensitive, these cannot be used as identifiers, variable name or any other purpose.
if, while, True, False, for, break, continue, or ...etc.

Identifiers: In programming languages, identifiers are names used to identify a variable, function, or other entities in a program.
The rules for naming an identifier in Python :
(i) Identifier must starts with alphabet or underscore (_).
(ii) Identifier cannot starts with digit or any special character.
(iii) It is preferred to keep variable name short and meaningful.
(iv) Keyword or reserved word cannot be used as identifier.
(v) We cannot use special symbols like !, @, #, $, %, etc. in identifiers.

IDLE stands for Integrated Development and Learning Environment provides two working modes—
(i) Interactive mode (popularly known as Python shell)
(ii) Script mode
The Python IDLE tool offers an interactive and a more efficient platform to write your code in Python.

Variables(Objects) whose values can be changed after they are created and assigned are called mutable.
Variables(Objects) whose values cannot be changed after they are created and assigned are called immutable.
Examples of mutable objects: list, dictionary, set
Examples of immutable objects: int, float, complex, bool, string, tuple

Operators are the symbols that operate (perform action) upon operands to form an expression. Operators available in Python are categorized as follows:

Arithmetic Operators
Assignment Operators
Relational or Comparison Operators
Logical Operators
Identity Operators
Bitwise Operators
Membership Operators

Identity Operators



Membership Operators

Python provides Input and Output built-in library functions:

input() function is used to read /get input from standard input device as string. The input() function takes one string argument (called prompt).

(i) For example to fetch your name into a variable my_name then python statement will be
my_name=input("Enter your name ")

(ii) Statement to get your age through keyboard
age=int(input("Enter your age "))

NOTE : eval() method takes a string as an argument, evaluates this string as a number, and returns the numeric result (int or float as the case may be). If the given argument is not a string or if it cannot be evaluated as a number, then eval() results in an error.



print( ): print( ) is a function which is used to display the specified content on the screen. The content (called argument) is specified within the parentheses. print( ) statement without any arguments will simply jump to the next line.

for example, to display a message "Hello World", the python statement will be:
print("Hello World")

to display the value of a variable
x= 10
print('Value of x is',x)

Changing a data type from one type to another data type is called Type casting. Type casting is of two types

Explicit Type Casting(forced type casting) when the programmer specifies interpreter to convert a data type into another type. For example : x=32.5 now explicitly we can convert int(x) to get 32

Implicit Type Casting when the interpreter automatically converts one data type to another. for example
a, b = 10, 5.5
c= a+b
here c will be automatically converted into float type.


Functions in Python that are used for explicitly converting an expression or a variable into a different type.
int(x) : Converts x into an integer.
float(x) : Converts x into a floating-point number.
str(x) : Converts x into a string representation.
chr(x) : Converts x into a character.
unichr(x) : Converts x into a Unicode character.