In this article, we will discuss getting started with python for CBSE class 11.
Getting started with Python
Python is a popular programming language due to its liveliness and pleasant productivity. It offers programming fun while coding. It was developed by Guido Van Rossum in February 1991 and further developed by the Python software foundation. It is a general-purpose programming language. Its syntax is easy and designed to give importance to the readability of code. It saves a few lines of codes with easy syntax rules. It is a powerful programming middle-level language but not so high-level language like C, C++, Java, etc.
- Easy to use: The syntax of python is very simple to use compared to other programming languages.
- Fewer Lines code: It offers few lines of code, a programmer can write multiple lines of in a single line.
- Use of interpreter: Python is using an interpreter, not a compiler that executes code line by line. So it is easy for a beginner.
- No additional library required: When python is installed, all basic libraries installed with it. So no need to install any standard library.
- Platform Independent: Python can run on any platform such as Windows, Linux/UNIX, Macintosh etc. Moreover, it can run on many devices like supercomputers, smartphones. It is a portable language.
- Free & Open Source: It’s free of cost and can be downloaded from www.python.org. It is open-source, so source code may be available for redistribution.
- Offers a variety of applications: Nowadays Python is used in many devices or applications such as Scripting, Web Development, Gaming, AI, Database Development etc.
Limitations – Getting started with Python
- Slow execution: Python uses an interpreter that executes code line by line which is slower in execution compared to a compiler-based programming language.
- Less no. of libraries: Python offers limited libraries compared to other programming languages like C, C++, etc.
- Not strong for mobile development: It is good for desktop or server-based applications but not efficient for mobile apps.
- Memory Consumption: Python offers flexible data types so there is high memory consumption.
- Weak in database connectivity: It is not that much strong like JDBC or ODBC, its database access layer has some barriers.
Now we will discuss how to install python into your computer or laptop which is first step of Getting started with Python.
Before starting programming with python, it needs to be installed. There are few distributions of python available like CPython (set of applications such as python interpreter, Python IDLE and Pip), Anaconda Python distribution (Comes with preloaded packages and libraries with IDEs like Spider, Jupyter, PyCharm etc.)
Download python from www.python.org for windows suitable executable installer. The latest version of python is 3.8.3.
Please refer to this documentation for installation steps: Documentation
After installation, you need to understand python interpreter which is mostly used to interpret your code in Getting started with Python.
Python interpreter offers two modes for coding:
- in Interactive mode
- in Script mode
Working in Interactive Mode
Interactive mode allows one to type one statement and executes the same line when the enter key is pressed. To start working in interactive mode follow these steps:
Step1. Click on Start → All Programs → Python 3.7 →IDLE (Python 3.7 64-bit).
Working in Script Mode
Working in script mode is an essential part when you are Getting started with Python.
To work in script mode follow these steps:
Step 1. Click on Start → All Programs → Python 3.7 →IDLE (Python 3.7 64-bit). A python shell will appear.
Step 2. Click File New. A new window will appear with the title “untitled”.
Step 3. Type the statement(s).
Step 6. The python shell display output like this:
After the understanding of print() function let’s move ahead with Getting started with Python tokens.
Tokens – Getting started with python
Tokens are the least units of programs. These tokens are as following:
Identifiers are names used in programs to identify small units of programs such as variables, objects, classes, functions etc.
Identifiers defined by the following few rules as follows:
- It must start alphabets
- It can be a combination of numbers and letters
- Special characters are not allowed in identifiers name
- Spaces are not allowed in identifier names, underscore can be used to separate two words
- The meaning of Upper Case and Lower Case different should not use as identifier names
- Few Examples:
- MyData, roll_no, year1 etc.
Keywords are python reserved words used in a program. Each and every keyword conveys special meaning to the python interpreter.
Ex.: def, False, if, elif, else, for etc.
Literals or Constants means that an item(s) have a fixed value. There are several types of constants or literals as follows:
- String Literals: Ex.: ‘a’, ‘abc’, ‘my_name’, ‘t’, ‘n’ etc.
- Numeric Literals: int, float, complex etc.
- Boolean Literals: True or False
- Special Literals: None
Operators – getting started with python
Operators are symbols or words used to perform the simple calculation or logical comparison in statement or expression. Python supports these operators:
- Unary Operators: It requires one operand Ex.: + (Positive), – (Negative), ~ (Bit wise complement), not (Logical Negation)
- Binary Operators: It requires more than one operators. They are as follows:
- Arithmetic Operators: + (Addition), – (Subtraction), * (Multiplication), / (Division), % (Modulus/Remainder), ** (Power), // (Floor division)
- Bitwise operator: & (AND), ^ (XOR), I (OR)
- Shift Operator: << (Shift left), >> (Shift Right)
- Identity Operators: is, is not (compare similar identity )
- Relational Operators: < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to), == (equal to), != (not equal to)
- Logical Operators: and (Logical AND), or (Logical OR)
- Assignment Operators: =, /=, +=, -=, *=, /=, %=, **=, //=
- Membership Operators: in, not in (use to check the variable is in sequence or not)
These tokens are very important for each program of python. So when you are getting started with Python you must understand each and every aspect of them.
That’s all from getting started with python share your valuable feedback about this chapter and read other topics for class 11 from below given links.