0% found this document useful (0 votes)
19 views10 pages

Python Notes - Save It For Later

Uploaded by

nvee nithesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
19 views10 pages

Python Notes - Save It For Later

Uploaded by

nvee nithesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
PYTHON NOTES 1, What is Python? ¢ Python is a high-level language like other high-level language such as Java, C++, PHP, Ruby, Basic and Perl. ¢ Python is an object-oriented programming language. * Python provides security. e The CPU understands a language which is called as Machine Language. Machine language is very complex and very troublesome to write because it is represented allin zero’s and one’s. The actual hardware inside CPU does not understand any of these high-level languages. 2, Program: e A Program can be defined as a set of instructions given to a computer to achieve any objective. ® Instructions can be given to a computer by writing programs. e Tasks can be automated by giving instructions to the computers. / %) Deepak Pandey, \ ) @iDeepakPandey 3. Defining Computer Hardware: Components: © CPU: It helpsin processing the instructions. ° Main Memory: It provides storage support during execution of any program in computer Eg: RAM. e The Secondary Memory: It helps to store the data permanently inside the computer. Eg: Disk drives, flash memory, DVD and CD. © The Input and Output Devices: © Input Devices helps users to generate any command or input any data. © Output Device helps user to get output from computer. Eg: Mouse, Printer, Keyboard, Monitor etc. 4. Constants and Variables: ¢ Variables can have any name, but Python reserved words cannot be used. e Avariable providesa named storage that the program can manipulate. Variables are named memory location used to store data in program which keeps on changing during execution. Programmers can decide the names of the variables. Fixed values used in programs such as numbers, letters and strings are called “Constants”. Values of constants never change during program execution. 5. Variable Naming Conventions: Must start with a letter or an underscore “_’ Must consist of a letters, numbers and underscores. Itisa case sensitive. Eg: First_Name, Age, Numi. Cannot be used: 1_hello, @hello, h123#2, -abe. Note: You cannot use reserved words for variable names and identifiers. 6. Mnemonic Variable Names « Use simple rules of variable namingand avoid reserved words. * While using simple rules, we have a lot of choice for variable naming. @ Initially this choice can be confusing either in reading or writing the program. The followingtwo programs are identical in terms of what they accomplish, but very different when you read and try to understand them: Eg 1: a=35.0 print(c) O/P: 437.5 Eg rate=12.50 pay=hours*rate print(pay) O/P: 437.5 7. Reserved Words in Python: « and, as, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield 8. Compilers and Interpreters: * Compiler is a computer program(or a set of programs) that transforms source code written in a programming language into another computer language. * Interpreters reads the source code of the program, line by line, passes the source code, and interprets the instructions 9, Python language: * The Python language acts as anintermediator between the end user and the programmer. Python script will have .py extensions Every one line can be a program in Python. Types of errors: A syntax error: It occurs when the “grammar” rules of Python are violated. A logic error: It occurs when the program has good syntax but there is a mistake in the order of the statements. Eg: © Using wrong variable name. o Makinga mistake ina Boolean expression o Indenting a block to the wrong level. o Using integer division instead of floating-point division. «® ASemantic error: It occurs when the description of the steps to take is syntactically perfect, but the program does not do what it was intended todo. a Difference between Programmers and Users * Programmers use software development tools availableina computerto develop software for the computer. = Aprogrammer may write the program to automate the task for himself or for any other client. " After learning programming language, the programmer can develop the software that can be utilized by end users. = Usersuse the tools availablein a computer like word processor, spreadsheet etc., whereas programmers learn the computer language and develop these tools. 12. Building blocks of a Program: These are some of the conceptual patterns that are used to construct a program: Input: Input will come from the user typing data on the keyboard. Output: Display the results of the program ona screen or store them ina file. Sequential Execution: Perform statements one after another in the order in which they are encountered in the script. Conditional Execution: Checks for certain conditions and then execute or skip a sequence of statements. Repeated Execution: Perform some set of statements repeatedly, usually with some variation. Reuse: Write a set of instructions once then reuse those instructions in the program. 13. Various Components of programmingstatements: © Variable. © Operator. © Constant. * Reserved Words. 14. Operators and its Precedence: * Operators are used to manipulate the values of operands. * There are various types of operators used in program: © Comparison (relational) operators. © Assignment operators. © Logical operators. Arithmetic Operators: @ Are the symbols that. are used to perform arithmetic ‘operations on operands. Types of Arithmetic operators: 2 1%: 16. ‘Comparison Operators: e Compares the values of an operands and decide the relation among them © They are also called as Relational Operators. Types of Comparison Operators: o <-less than © > greater than. © <=-less than equal to. © >= - greater than equalto. = equal to - not equal to. Logical Operators: © Are used to evaluate expressions and return a Boolean value Types of Logical Operators: © X&& y: Performs.a logical AND of the two operands. © x} Ly: Performs a logical OR of the two Operands. © Lx: Performs a logical NOT of the operand. 18. Logical Operators (Contd..): © There are three logical operators and, or and not. 20, The semantics of these operators is similar to their meaning in English. Eg: x>0 and x<10 (is true only if x is greater than 0 and less than 10). n%2==0 or n% 3==O(is true if either of the conditionis true). The not operator negates a Boolean expression. Eg: not(x>y) is true if x>y is false. Operator Precedence: When we use multiple operators in an expression, program must know which operator to execute first. This is called as “Operator Precedence”. The followingexpression multiple operators but they will execute as per precedence rule: © X=142*3-4/5**6, ¢ Egi: b=10,a=5, b%a O/P:0. Eg2: b=10,a=5, b%a==50/P: False. Highest Precedence rule to Lowest Precedence rule: Parentheses are always respected hence given first priority. Exponentiation (raiseto a power). Deepak Pandey; \ @iDeepakPandey’

You might also like