Python Intro

Python is a popular high-level programming language that is widely used in a variety of domains such as web development, scientific computing, data analysis, artificial intelligence, and more. Here are some key points to note about Python:

Simple and easy to learn: Python has a simple and readable syntax that makes it easy to learn for beginners. Its syntax is similar to the English language, making it easy to write and understand code.
Interpreted language: Python is an interpreted language, which means that the code is executed line-by-line at runtime rather than being compiled into machine code beforehand. This makes it easy to write and test code quickly, without the need for a separate compilation step.
Object-oriented: Python is an object-oriented language, which means that it supports the creation of objects and classes. This allows for modular and reusable code.
Cross-platform: Python is a cross-platform language, which means that it can be run on a variety of operating systems, including Windows, macOS, and Linux.
Extensive standard library: Python has a large and comprehensive standard library that includes modules for various tasks such as networking, regular expressions, file handling, and more. This makes it easy to perform many common tasks without having to write additional code.
Third-party libraries: Python has a vast ecosystem of third-party libraries and frameworks that can be easily installed and used, such as Django for web development, NumPy for scientific computing, and TensorFlow for machine learning.
High-level data structures: Python provides high-level data structures such as lists, dictionaries, and sets that make it easy to manipulate and work with data.
Dynamic typing: Python is dynamically typed, which means that the data type of a variable is determined at runtime rather than being specified beforehand. This can make programming faster and more flexible, but can also lead to potential errors if types are not carefully managed.
Strong community: Python has a strong and active community of developers who contribute to the language and its ecosystem through open-source projects, documentation, and support.

Overall, Python is a versatile language that is well-suited for a variety of tasks, and its ease of use, flexibility, and wide-ranging capabilities make it a popular choice for both beginner and experienced programmers.

Advantages of learning python

There are many advantages to learning Python. Here are some of the key benefits:

Versatile: Python is a general-purpose language that can be used in a wide variety of applications, including web development, data analysis, artificial intelligence, scientific computing, and more. This versatility makes it a valuable skill to have in many different industries.
Easy to learn: Python has a simple and readable syntax that makes it easy to learn for beginners. Its syntax is similar to the English language, making it easy to write and understand code.
Large and active community: Python has a large and active community of developers who contribute to the language and its ecosystem through open-source projects, documentation, and support. This means that there are many resources available for learning and problem-solving.
Comprehensive standard library: Python has a large and comprehensive standard library that includes modules for various tasks such as networking, regular expressions, file handling, and more. This makes it easy to perform many common tasks without having to write additional code.
Third-party libraries and frameworks: Python has a vast ecosystem of third-party libraries and frameworks that can be easily installed and used, such as Django for web development, NumPy for scientific computing, and TensorFlow for machine learning. This makes it easy to build complex applications and systems.
High-level data structures: Python provides high-level data structures such as lists, dictionaries, and sets that make it easy to manipulate and work with data.
Interpreted language: Python is an interpreted language, which means that the code is executed line-by-line at runtime rather than being compiled into machine code beforehand. This makes it easy to write and test code quickly, without the need for a separate compilation step.
Cross-platform: Python is a cross-platform language, which means that it can be run on a variety of operating systems, including Windows, macOS, and Linux.

Overall, learning Python can be a valuable skill for both beginners and experienced programmers. Its versatility, ease of use, and large ecosystem of resources make it a popular choice for many different applications and industries.

python libraries

Python has a vast number of libraries available for various purposes. Here are some commonly used Python libraries:

NumPy - for scientific computing and data analysis
Pandas - for data manipulation and analysis
Matplotlib - for data visualization
Seaborn - for statistical data visualization
Scikit-learn - for machine learning and data mining
TensorFlow - for deep learning
Keras - for building and training deep learning models
PyTorch - for building and training deep learning models
Flask - for web application development
Django - for web application development
Requests - for HTTP requests and API interactions
BeautifulSoup - for web scraping
NLTK - for natural language processing
OpenCV - for computer vision and image processing
Pygame - for game development.

These are just a few examples of the many Python libraries available, and the list is constantly growing as the Python community is very active in creating and maintaining libraries for various purposes.

Hello World

>>> print('hello world')

#Output hello world

Comments

# this is a comment
'''this is also a comment'''
"""this is also a comment"""
"""this
is a 
multi line
comment"""

Datatypes

TextString
Numericint,float,complex
Sequencelist,tuple,range
Mappingdict
Setset,frozenset
Booleanbool
Binarybytes,bytearray,memoryview
NonetypeNone

Strings

a = "hello"
b = ' world'
c = a+b
print(c) # hello world
print(type(c)) # <class 'str'>

Dictionary

d = {1:"one",2:"two",3:"three"}
print(d[1]) # 'one'
print(d.keys()) # dict_keys([1, 2, 3])
print(d.values()) # dict_values(['one', 'two', 'three'])
d[4] = "four"
print(d) # {1: 'one', 2: 'two', 3: 'three', 4: 'four'}
print(type(d)) # <class 'dict'>

Sets

s1 = {"a", "b", "c"}
s2 = set((1,2,3))
s2.update(s1)
print(s1) # {'a','b','c'}
print(s2) # {1, 2, 3,'a','b','c'}
print(type(s1)) # <class 'set'>

If and Else

a = 1
b = 0
if(a>b):
    print("true")
else:
    print("false")

If Elif Else

a = 10
if(a>0):
    print("a is positive")
elif(a<0):
    print("a is negative")
else:
    print("a equal to zero")

While Loop

a = 10
while a > 0:
    print(a)
    a = a-1

File Handling

a = open("t.txt","w")
a.write("python programming.")
a.write("python programming.")
a.close()
f = open("t.txt","r")
b = f.read()
f.close()
print(b)

Variables

x = 18
    y = "python"
    print(x,y) #output 18 python
    

Operators

x = 123
    y = 32
    z = x+y # z = 155
    print(x==y) # False
    print(x and y) # 32
    print(x & y) # 32
    print(x is y) # False
    

Numbers

x = 123
    y = 32
    z = x+y
    print(z) # 155
    print(type(z)) # <class 'int'>
    

Booleans

p = 12
    q = 32
    r = (p==q)
    print(p == q) # False
    print(type(r)) # <class 'bool'>
    print(bool(0)) # False
    print(bool(1)) # True
    

Lists

l = [1,2,3]
    n = "abcd"
    m = list(n)
    s = l+m
    print(s) # [1,2,3,'a','b','c','d']
    print(l*2) # [1,2,3,1,2,3]
    print(type(s)) # <class 'list'>
    

Tuples

l = (1,2,3)
n = "abcd"
m = tuple(n)
s = l+m
print(s) # (1,2,3,'a','b','c','d')
print(l*2) # (1,2,3,1,2,3)
print(type(s)) # <class 'tuple'>

Casting

i = 1
s = "5"
f = 10.09
print(int(f)) # 10
print(float(s)) # 5.0
print(str(f)) # '10.09'

For Loop

a = 10
for i in range(a):
    print(a)
    a = a-1

Functions

def add(x, y):
    print("x is %s, y is %s" %(x, y))
    print(x+y)
add(5, 6)
def add(x, y=10):
    print(x+y)
add(5)
add(5, 20)