Python Reserve Words and Data Types PYTHON by Ravinder Nath Rajotiya - April 19, 2019March 20, 20220 Setting the Path we started working with python in Calculator in Python. But it should also be noted that we need to set the path for the python if not set by default while installing python. This can be done on Windows Plateform as: set path=%path%;C:\python37 Typing an end-of-file character (Control-D on Unix, Control-Z on Windows) at the primary prompt causes the interpreter to exit with a zero exit status. If that doesn’t work, you can exit the interpreter by typing the following command: quit() Interactive Mode While working with python, we come across two types of prompts these are the primary and secondary prompt. primary prompt : when you start python prompt that appear is >>>. Secondary Prompt : … for continuous lines secondary prompt is … (three dots. >>> #
Strings and Lists in Python PYTHON by Ravinder Nath Rajotiya - April 19, 2019March 12, 20220 Strings Strings can be : Single quoted : 'Hello! I am here'. This is a single quoted string Double quoted : "Hello! i am here". This is double "" quoted string. Anything including escape sequence appear as it is, they are overridden Escape sequence be used anywhere (\n, \t, \a, \b and so on) Without print() string appear as it is, but with print () escape sequence have meaning In Python, single-quoted strings and double-quoted strings are the same. Pick a rule and stick to it. Improving readability When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability. Example: We can use raw string with ‘r’ in print() function as: Problems working with strings In many cases,
Calculator in Python PYTHON by Ravinder Nath Rajotiya - April 19, 2019June 10, 20190 Calculator In python calculator is at primary prompt. Just write any expression and you get the answer. Numbers: do the following a primary command prompt. So, you have an inbuilt calculator, we can write complex expression, it is always better to enclose them in parenthesis. See example below: A division operator always leaves the result as float. So 5/2=2.5 Whereas a floor operator (//) discard the fraction part, so 10/3= 3 Other operators are +, -, *, /, %, //, **, = In python last printed expression is assigned to variablele _ Example-1 Example-2 >>> x,y= 10,5 >>>z= x*y >>>w=_ + 5 >>>w 55 Note that now z =x*y to _ and add 5 to it to get 10*5 + 5 = 55 >>> tax = 12.5 / 100 >> >price = 100.50 >>>price * tax12.5625 >>> price +
Lists in Python PYTHON by Ravinder Nath Rajotiya - April 19, 2019March 12, 20220 Lists List is the most common composite data type in Python. It is is an ordered set of elements. Elements in a list can be of similar or different types. Declaration: A list in python is enclosed inside [ ] bracket. Elements in the list are separated by comma. Example of a list is: list1 = [8,6,7,4,5,3] When a list is created in Python, the interpreter creates a data structure in memory that is similar to an array (but not an array) to store it. The numbering in the list starts with 0, then 1, and so on, if accessed from the end indexing starts from -1, -2 and so on. myList = [3,2,6,4,9,’a’, ‘b’,’c’,‘ram’,’s’] myList 3 2 6 4 ‘a’ ‘b’ ‘c’ ‘ram’ ‘s’ Index from begining 0 1 2 3 4 5 6 7 8 Indexing from end -9 -8 -7 -6 -5 -4 -3 -2 -1 Real-Time Usage of the List The list data
Input-Outputs in Python PYTHON by Ravinder Nath Rajotiya - April 19, 2019May 10, 20210 Program to print a series of numbers Input function: Input(“Message”) #input characters and string Int(input(‘[message]”)) #input input values X=int(input(‘[message]”)) #returns integer value input from keyboard >>> x=input("Enter a Number:") Enter a Number :