0% found this document useful (0 votes)
9 views25 pages

Python Notes

Python is a versatile programming language created by Guido van Rossum in 1991, used for web development, software development, and mathematics. It features a simple syntax, supports multiple platforms, and allows for efficient coding with fewer lines. Python also includes functionalities like comments, variables, operators, modules, and a built-in math module for various mathematical operations.

Uploaded by

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

Python Notes

Python is a versatile programming language created by Guido van Rossum in 1991, used for web development, software development, and mathematics. It features a simple syntax, supports multiple platforms, and allows for efficient coding with fewer lines. Python also includes functionalities like comments, variables, operators, modules, and a built-in math module for various mathematical operations.

Uploaded by

olymptradingwork
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is Python?

Python is a popular programming language. It was created by Guido van Rossum,


and released in 1991.

It is used for:

 web development (server-side)


 software development
 mathematics

What can Python do?


 Python can be used on a server to create web applications.
 Python can connect to database systems. It can also read and modify files.
 Python can be used to handle big data and perform complex mathematics.
 Python can be used for production-ready software development.

Why Python?
 Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
 Python has a simple syntax similar to the English language.
 Python has syntax that allows developers to write programs with fewer lines
than some other programming languages.
 Python runs on an interpreter system, meaning that code can be executed as
soon as it is written.

Python Comments
Comments can be used to explain Python code.

Comments can be used to make the code more readable.

Comments can be used to prevent execution when testing code.

Single-Line Comments:
To write a comment just add a ‘#’ at the start of the line.

Multi-Line Comments:
To write multi-line comments you can use ‘#’ at each line or you can
use the multiline string.

Python Variables
Variables are containers for storing data values. Python has no command for
declaring a variable.

A variable is created the moment you first assign a value to it.

.Example:

Many Values to Multiple Variables


Python allows you to assign values to multiple variables in one line:

One Value to Multiple Variables


And you can assign the same value to multiple variables in one line:
Output Variables
The Python print() function is often used to output variables.

In the print() function, you output multiple variables, separated by a comma:


Python Operators
Python has different types of operators for different operations. They
are as follows:
Arithmetic operators:

Arithmetic operators are used to perform arithmetic/mathematical


operations.

Assignment operators:

These operators are used to assign values to variables.

Comparison operators:

These operators are used to compare values.


Logical operators:

These operators are used to deal with logical operations.

Type Casting
Similar to type conversion, type casting is done when we want to
specify a type on a variable.
Example:

Get the Type


You can get the data type of a variable with the type() function.
Output-
STRING
LIST AND TUPLE
DICTIONARY AND SET
CONDITIONAL STATEMENT (IF)
LOOPS (FOR & WHILE)
FUNCTIONS
MODULE
Module is a file that contains some functions & variables which can be imported for use in other files. Each
module should contain some related tasks. Example : math, random, string are built-in modules. The file name
is the module name with the suffix .py.

-Creating a module

# [Link]

def greet(name):

print("Hello”, name)

def square(x):

return x * x

- To use this module in another file, you can import it using the import statement:

import mymodule

[Link]("Alice") # Output: Hello, Alice!

print([Link](5)) # Output: 25

-If you have a module with a long name, you can use the as keyword to create an alias:

import mymodule as m

[Link]("Charlie") # Output: Hello, Charlie!

-To import/use only particular function from module use below statement:

from math import sqrt

print(sqrt(4)) # Output: 2
MATHS MODULE(Built-in module)
The math module in Python provides a wide range of mathematical functions and constants for
various mathematical operations. It is part of the standard library and does not require any
installation beyond the standard Python distribution. Here are some commonly used functions and
constants provided by the math module:

1. Constants:
 [Link]: The mathematical constant π (pi).
 math.e: The mathematical constant e (the base of natural logarithms).
2. Basic Mathematical Functions:
 [Link](x) : Returns the square root of x.
 [Link](x, y) : Returns x raised to the power y.
 [Link](x) : Returns e raised to the power x.
 [Link](x): Returns the smallest integer greater than or equal to x.
 [Link](x): Returns the largest integer less than or equal to x.
 [Link](x): Returns the truncated integer value of x.
 [Link](x): Returns the factorial of x.
3. Trigonometric Functions:
 [Link](x) , [Link](x) , [Link](x) : Returns the sine, cosine, and tangent of x,
respectively.
 [Link](x) , [Link](x) , [Link](x) : Returns the inverse sine, cosine, and tangent of
x, respectively.
 [Link](x) : Converts angle x from radians to degrees.
 [Link](x) : Converts angle x from degrees to radians.

Example-

You might also like