Download Python Programming: File Handling, Processes, and GUI with Tkinter and more Study notes Computer Science in PDF only on Docsity!
Table of Contents
- Python Features Introduction
- Python Installation
- Python IDEs and Code Editors
- General Format
- print Function
- Variables............................................................................................................................................................................ Variables and Data Types
- Data Types
- Identifiers
- Keywords
- Numbers Datatype
- String Datatype
- Boolean Datatype..............................................................................................................................................................
- Operator Type Operators
- Multiple Statements
- Multi-Line Statements.......................................................................................................................................................
- Multiple Assignments........................................................................................................................................................
- Comments
- Type Casting
- Input Function
- if…else Statements Condition and loop Structure
- if…elif…else Statements
- Ternary Operator
- while Loop
- while…else Loop
- for Loop
- range function
- for…else Loop
- break Statement
- continue Statement
- pass Statement..................................................................................................................................................................
- Function introduction Functions
- Function with Arguments..................................................................................................................................................
- Function with Default Arguments
- Function returning value
- Function Arbitrary Arguments
- Function Keyword Arguments
- Recursive Function
- Function Aliases / References
- Nested Functions
- Functions as Arguments
- Functions Returning Functions
- Function Decorator
- Anonymous Functions.......................................................................................................................................................
- Global Variable
- Local and Nonlocal Variable
- Closures
- Introduction Object-Oriented Programming
- Class
- Objects
- Constructors
- Destructor
- Class Variables...................................................................................................................................................................
- Class methods
- Static Methods
- Passing Object as Argument
- Special Method
- Operator Overloading
- Inheritance
- Inheritance Method Overriding
- Super( ) function
- Access Modifiers
- property function
- property decoratorn
- Polymorphism
- Abstract Methods and Classes
- Python Abstract Classes
- String Collection
- bytes Objects...................................................................................................................................................................
- bytearray Object
- Lists..................................................................................................................................................................................
- Tuple................................................................................................................................................................................
- Set
- Frozen sets
- Dictionary
- map function
- Array
- Module Introduction Modules
- Built-in Modules
- Import Statement............................................................................................................................................................
- from import Statement
- Renaming a module
- User defined Modules
- Packages
- Packages init....................................................................................................................................................................
- Subpackages
- Main Functions in Python
- Excepton Introduction Exception Handling
- Built-in Exceptions...........................................................................................................................................................
- try and except
- try and except…else block...............................................................................................................................................
- try and except…finally block
- raise statement
- custom Exception
- Iterators Introduction Iterators
- Iterable class
- StopIteration Exception
- Generators
- Yield statement
- Itertools module..............................................................................................................................................................
- Regular Expressions Introduction Regular Expressions
- Meta Characters..............................................................................................................................................................
- Re module
- Flags
- Match object
- Database Introduction Database
- SQLite Connection
- SQLite Create table
- SQLite insert,update,delete
- SQLite Retrieve records...................................................................................................................................................
- MySQL Connection
- MySQL Create table
- MySQL insert,update,delete
- MySQL Retrieve records..................................................................................................................................................
- Parameterized statement
- Datetime Introduction Datetime
- Date class
- Time class
- Datetime class
- Format Codes
- Timedelta class
- Calendar Module.............................................................................................................................................................
- time Module....................................................................................................................................................................
- File I/O Introduction File I/O
- File Open
- with statement
- File read...........................................................................................................................................................................
- File write..........................................................................................................................................................................
- Serialization
- Pickle module
- Binary File read
- Binary File write
- os module........................................................................................................................................................................
- os.path module
- Multithreading Introduction MultiThreading
- Threading module
- Thread class.....................................................................................................................................................................
- Daemon Thread
- Thread Synchronization
- Lock class
- Deadlock..........................................................................................................................................................................
- Multiprocessing Introduction Multiprocessing
- Multiprocessing module
- Process class
- Daemon Process..............................................................................................................................................................
- Process Synchronization
- Lock class
- Multiprocessing shared memory
- class Value
- class Array
- Managers
- SyncManager...................................................................................................................................................................
- BaseManager
- Process Pools...................................................................................................................................................................
- subprocess Introduction Subprocess
- Popen class
- Subprocess Function
- CompletedProcess
- Tkinter Introduction Tkinter
- Tkinter module
- Tk class
- mainloop
- Button
- Entry
- Variable classes
- Label
- Layout management
- Pack manager
- Grid manager
- Place manager
- spinbox
- scale.................................................................................................................................................................................
- Checkboxes
- Radio Buttons
- Listbox
- Canvas
- Message Box
- simpedialog
- File Chooser.....................................................................................................................................................................
- Color Chooser
- PhotoImage
- Menus
- Text..................................................................................................................................................................................
- Scrollbar
- Frame
- Label Frame
- Events and Binds
- Networking Introduction Networking
- Internet Protocol
- Sockets
- Class scoket
- Server scoket
- Client scoket
- sys Introduction sys Module
- Command Line Arguments
- stdin, stdout, stderr
- math Introduction math Module
- Constant
- Number-theoretic and representation
- Angular conversion
- Power and logarithmic
- Trigonometric..................................................................................................................................................................
- random Introduction random Module
- Functions for integers
- Functions for sequences
- Real-valued distributions
Python Features
Easy to Learn
It is more expressive means that it is more understandable and readable. More emphasis on the solution of the problem rather than the syntax
High-level Language
In Python, no need to take care about low-level details such as managing the memory used by the program.
Compiled Interpreted and Platform Independent
Internally, Python converts the source code into an intermediate form called byte code. This byte code is then executed by interpreter on PVM (Python virtual machine).
Free and Open Source
Python language is freely available at official web address. The source-code is also available. Therefore it is open source.
Hybrid language
Supports Procedural as well as Object Oriented Programing.
Embeddable
Python can be used within C/C++ program i.e. in other languages.
Robust
Exception handling features Memory management techniques in built.
Rich Library Support
The Python Standard Library is vary vast. Library available for NLP, multi-threading, databases, CGI, email, XML, HTML, Image , Audio , Video Processing , cryptography, GUI, Networking and many more.
Python Installation
It is highly unlikely that your Windows system shipped with Python already installed. Windows systems typically do not. Fortunately, installing does not involve much more than downloading the Python installer from the python.org website and running it. Python installers are available for download - two each for the 32-bit and 64 - bit versions of the interpreter. The web installer is a small initial download, and it will automatically download the required components as necessary. The offline installer includes the components necessary for a default installation and only requires an internet connection for optional features.
- Open a Web browser and go to http://www.python.org/download/
- Double click on downloaded installer
- Check on (Add python to path). Click on customize installation.
Python IDEs and Code Editors
A code editor is a tool that is used to write and edit code. They are usually lightweight and can be great for learning. However, once your program gets larger, you need to test and debug your code, that's where IDEs come in. An IDE (Integrated Development Environment) understand your code much better than a text editor. It usually provides features such as build automation, code linting, testing and debugging. This can significantly speed up your work.
- IDLE 2. PyCharm 3. Visual Studio Code
IDLE
When you install Python, IDLE is also installed by default. This makes it easy to get started in Python. Its major features include the Python shell window(interactive interpreter), auto-completion, syntax highlighting, smart indentation, and a basic integrated debugger. IDLE is a decent IDE for learning as it's lightweight and simple to use. However, it's not for optimum for larger projects.
PyCharm
PyCharm is an IDE for professional developers. It is created by JetBrains, a company known for creating great software development tools. There are two versions of PyCharm: Community - free open-source version, lightweight, good for Python and scientific development Professional - paid version, full-featured IDE with support for Web development as well PyCharm provides all major features that a good IDE should provide: code completion, code inspections, error-highlighting and fixes, debugging, version control system and code refactoring. All these features come out of the box.
General Format of python Program
print Function
The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.
Syntax:
Arguments Discerption
objects Object to the printed. * indicates that there may be more than one object
separator Optional. objects are separated by separator. Default value: ' '
end Optional. end is printed at last Default is '\n'.
file Optional. Must be an object with write(string) method. If omitted it, sys.stdout will be
used which prints objects on the screen.
flush Optional. If True, the stream is forcibly flushed. Default value: False
For Example:
To print string
• Import statement
• Global declaration
variables
functions
classes
• Statements
print(*objects,sep=' ',end='\n',file=sys.stdout,flush=False)
print(“Welcome to Python”)
>>>Welcome to Python
To print value store in variable and String
To print value store in variable
To print formatted String
To print formatted String
To print formatted String
To print separator String
A=”Python”
print(“Welcome to”,A)
>>>Welcome to Python
A=”Ram”
B=”Seeta”
print(A , B)
>>>Ram Seeta
A=”Python”
print(f“Welcome to {A}”)
>>>Welcome to Python
A=”Welcome”
B=”Python”
print(“{0} to {1}”.format(A,B))
>>>Welcome to Python
A="Ram"
B="Seeta"
print(B,A,sep="->")
>>>Seeta->Ram
A=”Welcome”
B=”Python”
print(“%s to %s”%(A,B))
>>>Welcome to Python
Variables
A variable is a location used to store data in the memory. It is helpful to think of variables as a container that holds data which can be changed later throughout programming. In Python, we don't need to specify the type of variable because Python is a dynamically-typed. It automatically decides the datatype depending on type of value.
Syntax:
For Example:
Data Types
Variables can store data of different types, and different types can do different things. Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes. There are various data types in Python. Some of the important types are listed below.
Text Type String
Numbers Integer , Float, complex
Sequence Types List, Tuple ,Sets
Mapping Type Dictionary
Boolean Type Bool
Binary Types Bytes, Bytearray
Variable_Name = Value ;
A=
B=”CCIT”
C=True
Identifiers
Python Identifier is the name we give to identify a variable, function, class, module or other object. That means whenever we want to give an entity a name, that’s called identifier.
Rules:
Identifier must start with a letter or the underscore character
Next can be alphabets digits or underscores.
Variable names are case-sensitive.
No max limit.
Keywords
Python keywords are the words that are reserved. That means you can’t use them as name of any entities like variables, classes and functions. So you might be thinking what these keywords are for. They are for defining the syntax and structures of Python language. You should know there are 33 keywords in Python programming language as of writing this tutorial. Although the number can vary in course of time. Also keywords in Python is case sensitive. So they are to be written as it is. Here is a list of all keywords in python programming.
false none in while assert
def import try as finally
if return and except nonlocal
raise true else lambda yield
del elif is with pass
break not class grom
for or continue global