Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Python Basic Notes

Uploaded by

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

Python Basic Notes

Uploaded by

Samyucktha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Introduction to Python

Python is an easy-to-read, high-level, interpreted programming language known for its simplicity
and versatility.

2. Variables and Data Types

● Variables store data values. In Python, you don’t need to declare the type of a variable,
as it is dynamically typed.
● Data Types: Python has several built-in data types including:
○ Integers (int)
○ Floating point numbers (float)
○ Strings (str)
○ Lists (list)
○ Dictionaries (dict)
○ Tuples (tuple)
○ Booleans (bool)

3. Basic Syntax
Comments: Use # for single-line comments and triple quotes for multi-line comments.
python
# This is a single-line comment
"""
This is a
multi-line comment
"""

Print Statement: Display output using print().


python
print("Hello, World!")

4. Control Flow
If Statements: Used to execute code based on conditions.
python
if condition:
# code
elif another_condition:
# code
else:
# code

5. Loops
For Loops: Iterate over a sequence.
python
for element in sequence:
# code

While Loops: Repeat code as long as a condition is true.


python
while condition:
# code

6. Functions

Functions are blocks of reusable code.

python
def function_name(parameters):
# code
return value

7. Libraries and Modules

You can extend Python’s functionality with libraries and modules using import.

python
import math
print(math.sqrt(16)) # Outputs 4.0

8. Basic Input/Output
Input: Get user input using input().
python
name = input("Enter your name: ")
print("Hello, " + name)

9. Error Handling

Handle errors using try and except.

python
try:
# code that might raise an error
except Exception as e:
print("An error occurred:", e)

10. File Handling

Read and write files using built-in functions.

python
with open('file.txt', 'r') as file:
content = file.read()

You might also like