Introduction to Python Basics for begineers.pptx

namrabsit 22 views 10 slides Oct 19, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

python basics for beginners


Slide Content

Chapter 2: A Crash Course in Python

Python Basics - Python is a general-purpose language used for data science. - It is dynamically typed and has simple syntax. - Example: Printing 'Hello, World!': ```python print("Hello, World!") ```

Arithmetic Operations in Python - Python supports basic arithmetic operations like +, -, *, /. - Example: ```python x = 5 + 3 # Addition y = 7 - 2 # Subtraction z = 8 * 4 # Multiplication q = 9 / 3 # Division ```

Variables in Python - Variables store data in Python. - Variable names must start with a letter or underscore. - Example: ```python my_variable = 10 another_variable = 3.14 print(my_variable, another_variable) ```

Strings in Python - Strings are sequences of characters. - You can concatenate strings using `+` and repeat them using `*`. - Example: ```python hello = "Hello, " world = "World!" greeting = hello + world print(greeting) ```

Lists in Python - Lists are ordered collections of items. - They can hold different data types. - Example: ```python my_list = [1, 2, 3, 'a', 'b'] my_list.append(4) print(my_list) ```

Dictionaries in Python - Dictionaries store key-value pairs. - Keys must be unique, and values can be of any type. - Example: ```python my_dict = {'a': 1, 'b': 2} my_dict['c'] = 3 print(my_dict) ```

Control Flow in Python - Control flow includes if-else statements and loops. - Example: ```python for i in range(5): if i % 2 == 0: print(f"{i} is even") else: print(f"{i} is odd") ```

Functions in Python - Functions allow reusability of code. - Define a function using the `def` keyword. - Example: ```python def greet(name): return f"Hello, {name}!" print(greet('Alice')) ```

List Comprehensions - List comprehensions provide a concise way to create lists. - Example: ```python squares = [x**2 for x in range(10)] print(squares) ```