Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Class :XI
L-3 Brief overview of Python
An ordered set of instructions or commands to be executed by a computer is called a program. The language used to specify those set of instructions to the computer is called a programming language for example Python, C, C++, Java, etc. This chapter gives a brief overview of Python programming language. Python is a very popular and easy to learn programming language, created by Guido van Rossum in 1991. It is used in a variety of fields, including software development, web development, scientific computing, big data and Artificial Intelligence. The programs given in this book are written using Python 3.7.0. Execution Modes : There are two ways to run a program using the Python interpreter: a) Interactive mode b) Script mode (A) Interactive Mode- In the interactive mode, we can type a Python statement on the >>> prompt directly. As soon as we press enter, the interpreter executes the statement and displays the result(s). Working in the interactive mode is convenient for testing a single line code for instant execution. But in the interactive mode, we cannot save the statements. (B) Script Mode- In the script mode, we can write a Python program in a file, save it and then use the interpreter to execute the program from the file. Such program files have a .py extension and they are also known as scripts. Usually, beginners learn Python in interactive mode, but for programs having more than a few lines, we should always save the code in files for future use. Python scripts can be created using any editor. Python has a built-in editor called IDLE which can be used to create programs. After opening the IDLE, we can click File>New File to create a new file, then write our program on that file and save it with a desired name. By default, the Python scripts are saved in the Python installation folder. IDLE : Integrated Development and Learning Environment To execute a Python program in script mode, a) Open the program using an editor b) In IDLE, go to [Run]->[Run Module] to execute the program c) The output appears on shell Python Keywords - Keywords are reserved words. Each keyword has a specific meaning to the Python interpreter. As Python is case sensitive, keywords must be written exactly as given in Table Python keywords False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise 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 are as follows: • The name should begin with an uppercase or a lowercase alphabet or an underscore sign (_). This may be followed by any combination of characters a- z, A-Z, 0-9 or underscore (_). Thus, an identifier cannot start with a digit. • It can be of any length. (However, it is preferred to keep it short and meaningful). • It should not be a keyword or reserved word. • We cannot use special symbols like !, @, #, $, %, etc. in identifiers. Variables - Variable is an identifier whose value can change. For example variable age can have different value for different person. Variable name should be unique in a program. Value of a variable can be string In Python, we can use an assignment statement to create new variables and assign specific values to them. gender = 'M' message = "Keep Smiling" price = 987.9 Variables must always be assigned values before they are used in the program, otherwise it will lead to an error. Wherever a variable name occurs in the program, the interpreter replaces it with the value of that particular variable. Literals : Literals are the pool of data items that have fixed values. Python allows several kinds of literals: (a) string literals (b) Numerical literals (c) Boolean Literals (d) Special Literal None Operators - Operators are special symbols which trigger some computation and action when applied to variables or identifiers. Variables or identifies to which computation is applied are called operands. Punctuators - Punctuators are the symbols that are used in programming languages to organize the sentence structures, and indicate the rhythm and emphasis of program structure. Most common punctuators are ‘ “ \ ( ) { } [ ] @ . =