PYTHON





PYTHON:
A high-level programming language.
Expresses the code in a fewer lines.
Can be used for everything from web development to software or scientific applications.

High level programming language:
Focusing more on logic rather than hardware components such as addressing.
 
Downloading and installing Python:
Go to website www.python.org.
Download windows 64 bit executable code.





Hello world program in python:


Variable:
Stores the value and assigns memory location and it not fixed.

How to assign a value to variable in python:



Data type:
Specifies which type of value in a variable and what type of action is to be performed without causing error.

Int: Non limited length in python.
Boolean:
Used to represent true or false.

Float:
Equivalent to double in C.
Complex:
String:
List: More memory is assigned to a variable.
Tuple: In tuple a fixed memory is assigned to variable.
Dictionary: Key and value are separated by comma. Keys are unique in dictionary.

String manipulation:
List of characters in order.
Accessing a string:

Count:
Slicing:
Replace:
Reverse:
Strip, lstrip, rstrip:
Strip removes both starting and ending spaces.
LStrip removes left spaces.
Rstrip removes right spaces.

Concatenation:
Starts with:
Ends with:

Count the no of occurrences of a sub-string in given string:
 
Loops:
Allows to execute a statement for multiple times.
For loop, While loop.

For loop:
Executes the statement for particular repetition.
Syntax: for <variable> in <sequence>:
                    Statements
Example:
 
While loop:
Repeats a statement while the condition is true.
Syntax: while(condition):
                Statement
Example:

Loop control statements:
Change the execution from a normal flow of program.
Break, continue, pass statements.

Break statement:
If you are using nested loops break statement stops the innermost loop and starts executing the statement.

Continue statement:
Makes the statement to continue.

Pass statement:
When a statement is required syntactically but you do want any command to execute.
 
Sorting:

Function:
Block of organized reusable code that is used to perform single, related action.

Defining a function:
Syntax: def function_name(parameters):
                    Statement
              return

Calling a function:
Function_name('data')

Conditional execution:
Provides different action based on whether a programmer provided true or false.
If, If-else.

If:
Syntax: if expression:
                  Statements

If-else:
Syntax: if expression:
                 Statements
             else:
                  Statements

Mathematical functions:

Turtle:
Python feature like a drawing on board.
For drawing we need a function turtle.forward(), turtle.left(), turtle.backward(), turtle.right().

Drawing a rectangle:

Drawing a line:

Drawing a circle:
We have to create an instance of Turtle object.
 
Drawing a star:

How to take input from command prompt:
Input is the keyword to take the values.

Read and write files:
File means contains all the information stored in a particular place.

Count the no of occurrence of a string and replace with another string:


 
Parsing a file:
Process of analyzing a string or symbol.

Program for finding first non-repeated character in string:
In getChar function we are converting into dictionary type.
FirstNon function we are checking for non repeated character.

Program for finding a permutation of a string:

Program for finding digit identification if string contains numbers:


Downloading and installing mysql:







Installing connector in python:




Retrieving data from database in python:
Retrieving means obtaining data from database.

Drawing shapes:

You Might Also Like