0% found this document useful (0 votes)
5 views4 pages

المستند 103

These class notes cover the basics of Python programming, including its high-level syntax and applications in various fields. Key topics include basic syntax, variables and data types, data structures, control structures, functions, file handling, and exception handling. The notes provide examples of each concept to illustrate their usage in Python.

Uploaded by

hsgstgas
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)
5 views4 pages

المستند 103

These class notes cover the basics of Python programming, including its high-level syntax and applications in various fields. Key topics include basic syntax, variables and data types, data structures, control structures, functions, file handling, and exception handling. The notes provide examples of each concept to illustrate their usage in Python.

Uploaded by

hsgstgas
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
You are on page 1/ 4

:**Alright!

Here are some brief class notes on **Python Basics

**Python Basics – Class Notes** ###

**Introduction to Python .1** ####

.Python is a high-level, interpreted programming language -

.Known for its simple syntax, making it easy to learn and read -

Used in web development, data analysis, AI, machine learning, and -


.more

**Basic Syntax .2** ####

**:Print statement** -

python```

!Print("Hello, World!") # Outputs: Hello, World

```
**:Comments** -

`Single-line comment: `# This is a comment -

:Multi-line comment -

python```

"""
This is a

Multi-line comment

"""
```

**Variables and Data Types .3** ####

.Variables store data values. No need to declare type explicitly -

python```
Name = "Alice" # String

Age = 25 # Integer

Height = 5.6 # Float

Is_student = True # Boolean

```

**Data Structures .4** ####

.List:** Ordered, mutable collection** -

python```

Fruits = ["apple", "banana", "cherry"]

Print(fruits[0]) # apple

```
.Tuple:** Ordered, immutable collection ** -

python```

Coordinates = (10, 20)

```
.Dictionary:** Key-value pairs** -

python```

Person = {"name": "Bob", "age": 30}

Print(person["name"]) # Bob

```
.Set:** Unordered collection of unique elements ** -

python```

Numbers = {1, 2, 3, 3} # {1, 2, 3}

```

**Control Structures .5** ####

**:Conditional Statements** -

python```
:If age > 18

Print("Adult")

:Elif age == 18

Print("Just turned adult")

:Else

Print("Minor")

```

**:Loops** -

:For loop -

python```

:For fruit in fruits

Print(fruit)

```
:While loop -

python```

Count = 0

:While count < 5

Print(count)

Count += 1

```

**Functions .6** ####

.Reusable blocks of code that perform a specific task -

python```

:Def greet(name)

"!Return f"Hello, {name}

!Print(greet("Alice")) # Hello, Alice


```

**File Handling .7** ####

:Reading a file -

python```

:With open('file.txt', 'r') as file

)(Content = file.read

```
:Writing to a file -

python```

:With open('file.txt', 'w') as file

File.write("Hello, World!")

```

**Exception Handling .8** ####

:Handle errors gracefully using `try-except` blocks -

python```

:Try

Result = 10 / 0

:Except ZeroDivisionError

Print("Cannot divide by zero.")

```

Want notes on anotherr topic or a deeper dive into one of these


?sections

You might also like