The document provides an overview of important concepts for Python including:
- Python's creator, its features as an interpreted, object-oriented, cross-platform language.
- Details on Python's interactive shell, syntax conventions like indentation and comments.
- Common data types like integers, floats, strings, lists, tuples, dictionaries.
- Operators, functions, modules, files and file I/O methods like open, read, write.
- Control flow statements like if/else, for loops, functions.
- Details on CSV and binary files, serialization, common string and list methods.
The document provides an overview of important concepts for Python including:
- Python's creator, its features as an interpreted, object-oriented, cross-platform language.
- Details on Python's interactive shell, syntax conventions like indentation and comments.
- Common data types like integers, floats, strings, lists, tuples, dictionaries.
- Operators, functions, modules, files and file I/O methods like open, read, write.
- Control flow statements like if/else, for loops, functions.
- Details on CSV and binary files, serialization, common string and list methods.
The document provides an overview of important concepts for Python including:
- Python's creator, its features as an interpreted, object-oriented, cross-platform language.
- Details on Python's interactive shell, syntax conventions like indentation and comments.
- Common data types like integers, floats, strings, lists, tuples, dictionaries.
- Operators, functions, modules, files and file I/O methods like open, read, write.
- Control flow statements like if/else, for loops, functions.
- Details on CSV and binary files, serialization, common string and list methods.
The document provides an overview of important concepts for Python including:
- Python's creator, its features as an interpreted, object-oriented, cross-platform language.
- Details on Python's interactive shell, syntax conventions like indentation and comments.
- Common data types like integers, floats, strings, lists, tuples, dictionaries.
- Operators, functions, modules, files and file I/O methods like open, read, write.
- Control flow statements like if/else, for loops, functions.
- Details on CSV and binary files, serialization, common string and list methods.
Class XII CS-083 Important Points for Term-1 Sweeti Kakhani
Python developer: Guido Van Rossum. Write in C language
Python: cross platform, free and open source, object oriented, interpreted high level language. Free and open source: not to pay for use and source code is available for modification. Cross platform: work on variety of operating system. Interpreted: execute code line by line Python shell: interactive interpreter Python prompt: >>> Python is case sensitive: capital and small letters treat different. Two modes of working: interactive and scripting mode. Interactive: use for testing, debugging , immediate response and write one command at a time Scripting: use for create and save program/software, write multiple command and output is on another shell. Program: set of instructions Keyword: reserve words having a special meaning(learn 33 keywords) Literals: constant(value is fixed) None: absence of value. Also show end of list value. Single line comment: # Multi line comment: triple quote “”” “”” or ‘’’ ‘’’ Arithmetic operator: +, -, *, /, //(floor division:only integer division), **(exponent:raise to power), %(modulus:remainder) Logical operator: and, or, not Bitwise operator: &(and), |(or), ^(Xor) Identity operator: is, is not Membership operator: in, not in Assignment operator: =, +=(augmented assignment operator) etc. Operator precedence: 1:(),2: (**),3: (*,/,//,%), 4: (+,-), Indentation: group of one or more statement. Also called block A=b=20 means 20 is assign to both a and b. A,b=2,3 means a=2 and b=3; assign values order wise. Dynamic typing: changing the data type of variable automatically according to users assignment. Print(): use to display the message as it is and also display the value of variable. Input(): use to take(read) values from the user. It returns the entered values in string type only. Int(), float(), char(), str() are type conversion function. Print(): print a blank line. Type(): show the data type of a object. Id(): show the address of the variable. data types: numbers(int,float,complex), sequence(string,list,tuple), mapping(dictionary),set,None mutable: at the same address new value can be stored. mutable data type(changeable/modifiable): list,dictionary,set immutable(memory address not changeable): integer, float, Boolean, string, tuple empty statement: which does nothing. example is : pass selection statement: if else iteration/looping: repetition of set of statement (for, while, do while) range(start,end,step value): generate sequence and used in for loop. By default start=0 , end=n, step=1 and all values should be integers. Syntax : for <var> in <sequence> or for <var> in <range()> Jump statement: break,continue Break: exit from the loop Continue: skip the rest code of the body of loop and continue with the next iteration. Debugging: identifying and removing errors Syntax Errors: violation of grammatical rules Logical Errors: not stop execution but the program behaves incorrectly Runtime Error: abnormal termination of program. Division by zero String Positive indexing: 0 to n-1(start from left), Negative indexing: -n to -1(start from right) Traversing a String: Access each element of the string. Concatenation: to join two strings (+) Repetition/replication: repeat the given string n times. str1*n Slicing: access some part of a string str1[start : end : step_value] ; start with 0 and end with m-1 and step_value is 1.. len() : Return total characters in the string. partition() : partitioned into three parts. split() : Returns a list of words delimited by the specified substring. Sorting: arrange data in ascending or descending order 2+3=5 but “2”+”3”=23 but 2+”3” is invalid 2*3=6 but “2”*”3” is invalid but “2”*3=”222” List: [ ] and mutable. list is an ordered sequence of one or more elements with different data types. Index is integer. List + list ; + works as concatenation. List+any_number; error (integer number is not allowed.) Tuple: ( ) tuple is an ordered sequence of elements of different data types. Index is integer. T+T; + works as concatenation. Difference b/w list and tuple is Mutability. Dictionary { }: unordered. Mutable. dictionary index value can be any other data type. dict = {'key1': 'value1','key2': 'value2'} t = (20,) is tuple , t=1,2,5 is tuple but t=(20) is not tuple module: is a Python file(.py) containing a set of functions. Using import: All functions included. Using from statement: include only defined functions. random():Random Real Number (float) in the range 0.0 to 1.0. no argument pass randint(x,y): Random integer between x and y. 2 argument compulsory randrange(y): at least 1 argument compulsory. len(): return total elements in list. Count():Returns the number of times a given element appears in the list. append() Appends a single element at the end of the list extend() Appends multiple elements at the end of the list insert() Inserts an element at a particular index. 2 arguments must. sort() Sorts the elements in the same list sorted()creates a new list with elements are arranged in ascending order. Function: Functions are the subprograms/independent block of code that perform specific task. Function header syntax: def fun_name([arguments]) : The default parameters must be the right most parameters in the function header. Required arguments/Positional parameter -arguments passed in correct positional order. Keyword arguments: arguments identified by the parameter name with value. File: sequence of bytes, stored permanently on secondary storage device. text file: human readable characters, contain sequence of ASCII , Store only plain text, Each line ends with the End of Line (EOL), extensions are .txt, .py, .csv Binary files: non-human readable characters, store different types of data (audio, text,image), extension are .exe file, MP3 file, image file, .dat file, .bin file CSV: Comma separated value files; values are separated by comma, store big data sets. Absolute path: full path to some place Relative path: path with respect to your current working directory (PWD). Access mode Purpose File offset R Reading Beginning of file R+ Read and write Beginning of file Rb Read binary file Beginning of file W Write(if file exist then overwrite otherwise Beginning of file new file create) W+ Write and read Beginning of file Wb Write binary file Beginning of file A Append(if file not exist then create new file End of the file otherwise content added at last) A+ Append and read End of the file Open file: file_obj= open(“file_ name”,”access_mode”) Closed : is a attribute and gives result true if the file is closed. Close() : is a function for closing a file. File_obj.close() Open file with with clause: it will close file automatically. Write to the file: 1. write() - for writing a single string. Take argument as string and return number of characters and end with \n. 2. writelines() - for writing a multiple strings(list/tuple). Not return number of characters. Read a file: 1. read(n)-read a specified number of bytes of file. If no argument then read all content of file. 2. Readline()-read a specified number (n) of bytes upto \n(new line). If no argument then reads one complete line. 3. Readlines(n)- Read number of lines from file. If no argument then reads all the lines and returns list of strings. Setting Offsets: 1. Tell(): tells current position 2. seek(offset,ref_point): used to changes the current file position. By default ref_point value is 0(beginning of the file) Binary file: Pickle module is used for binary files. Serialization/pickling : convert python object/data from memory to byte stream in database/disk. Dump() De-serialization or unpickling: byte stream is converted back to Python object. Load() pickle module: dump() and load() 1. dump(data,b_file_obj):writing/store data in a binary file. 2. load(b_file_obj):to load (unpickling) data from a binary file csv file operations: 1. csv.writer(): create writer object to call writerow() method to write objects. 2. csv.reader(): method to read each row of the file.
A Turing Machine Is A Mathematical Model of Computation That Defines An Abstract Machine That Manipulates Symbols On A Strip of Tape According To A Table of Rules