Skip to main content

Posts

Showing posts with the label Python programming

INTRODUCTION TO PYTHON

HISTORY OF PYTHON Python was developed by  Guido van Rossum  in 1989 at the  National Research Institute for Mathematics and Computer Science  in  Netherlands . Python got its name from a  BBC comedy series  from seventies- “ Monty Python’s Flying Circus ”. FEATURES OF PYTHON EASY TO READ AND WRITE  : Python is easy to read and write. It is developer-friendly. Reading a good Python program feels almost like reading English (but very strict English!). This pseudo-code nature of Python makes it easy to learn and use. SUPPORTS DIFFERENT PROGRAMMING PARADIGMS:  Python supports procedure-oriented programming as well as object-oriented programming. EASILY EXTENSIBLE  : It is easily extensible. It implies that other languages such as C/C++ can be used to compile the code and which can be used further in our python code. HIGH LEVEL PROGRAMMING LANGUAGE  : When we write programs in Python, we never need to bother about low-level details such as managing the memory us

PYTHON DATA TYPES AND VARIABLES

DATA TYPES AND VARIABLES LEARNING OBJECTIVES At the end of this chapter students will be able to understand Concept of tokens: keywords, identifiers, literals, operators and delimiters Notion of a variable and methods to manipulate it Assigning values to variables output a variable input a variable Data Types: Numbers, String, List, Tuple, Dictionary Data type conversion: Implicit and Explicit Comments TOKENS Tokens are the smallest individual unit of a program. Following are the tokens in Python: keywords, identifiers, literals, operators, and delimiters   . KEYWORDS They are the words used by Python interpreter to recognize the structure of program. As these words have specific meaning for interpreter, they cannot be used for any other purpose. To get a list of Keywords in the Python version installed on your computer, you can type the following commands at the prompt: >>> import keyword  >>> keyword.kwlis

PYTHON OPERATORS AND EXPRESSIONS

OPERATORS AND EXPRESSIONS LEARNING OBJECTIVES At the end of this chapter students will be able to understand Types of Operators: Arithmetic Operators Relational Operators Assignment Operators Logical Operators Precedence of Operators Python Expressions Indentation OPERATORS Operators are used to perform some action on data. There are 6 different types of operators: Arithmetic Unary   They require a single operand to perform an operation. They can precede or follow their operands. For eg. unary +, unary -, increment/decrement operator. OPERATOR DESCRIPTION EXAMPLE UNARY - To make the value of the number negative -5 UNARY + To make the value of the number positive +5 Binary  They require two operands to perform an operation. For eg. +, -, *, /, % . OPERATOR DESCRIPTION EXAMPLE + Add two operands 10+5=15 - Subtracts two operands 10-5=5 * Multiplies two operands 10*5=50 / Divides two operands and gives quotient

PYTHON SELECTION STATEMENTS

SELECTION STATEMENTS LEARNING OBJECTIVES At the end of this chapter students will be able to understand Concept of flow of control Selection/Conditional Statements: if. . . . else Nested if Use of Conditional Expression FLOW OF CONTROL In a program, the execution of statements can be sequential, selective, or iterative. Sequential Construct It is the default flow of statements and causes execution of statements in a sequential or linear order. Selection/Conditional Constructs It means execution of statements on the basis of a condition. If the condition is true, one group of statements is executed otherwise another group of statements is executed. Iterative/Looping Constructs It means repetition of a set of statements depending upon a condition. The set of instructions are executed repeatedly till a certain condition is true. SELECTION/CONDITIONAL STATEMENTS The selection statement allows us to choose a set of instructions for execution