0% found this document useful (0 votes)
4 views

Python Programming Basics Syntax, Functions, And Tips

Uploaded by

IDK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Programming Basics Syntax, Functions, And Tips

Uploaded by

IDK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Programming Basics: Syntax, Functions, and Tips

Python Programming Basics: Syntax, Functions, and Tips

1. Variables and Data Types:

- Examples: `x = 10`, `name = "Alice"`

- Common types: int, float, str, list, dict.

2. Control Structures:

- If-else: `if x > 0: print("Positive") else: print("Negative")`

- Loops: `for i in range(5): print(i)`

3. Functions:

- Defining: `def greet(name): return f"Hello, {name}"`

- Calling: `greet("Bob")`

4. Modules:

- Importing: `import math`

- Using: `math.sqrt(16)`

5. Tips:

- Use comments for readability: `# This is a comment`

- Debugging: Use `print()` or IDE debuggers.

Code Snippet Example:

```
def factorial(n):

if n == 0:

return 1

else:

return n * factorial(n-1)

print(factorial(5)) # Output: 120

```

You might also like