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

Python_Notes_Fixed-1

The document provides comprehensive notes on Python basics, covering topics such as variables, arithmetic operations, type conversions, and Jupyter Notebook shortcuts. It includes examples for functions, boolean values, lists, loops, list comprehensions, strings, dictionaries, and external libraries. The notes emphasize Python's unique features like direct list swapping and the use of built-in functions.

Uploaded by

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

Python_Notes_Fixed-1

The document provides comprehensive notes on Python basics, covering topics such as variables, arithmetic operations, type conversions, and Jupyter Notebook shortcuts. It includes examples for functions, boolean values, lists, loops, list comprehensions, strings, dictionaries, and external libraries. The notes emphasize Python's unique features like direct list swapping and the use of built-in functions.

Uploaded by

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

Python Basics - Comprehensive Notes

1. Variables and Print Statements

No need to declare variables before assigning them.


Use print() to display output. Python code blocks are determined by indentation.

Example:
x = 10
print(x) # Output: 10

2. Arithmetic Operations

* operator can multiply strings with numbers.


Example:
print('Spam ' * 4) # Output: Spam Spam Spam Spam

3. Type Conversions

int(3.33) -> 3
float(10) -> 10.0
int('100') + 1 -> 101

4. Jupyter Notebook Shortcuts

Esc + A -> Create a new cell above


Esc + B -> Create a new cell below

5. Power Operator

a ** b calculates power.
Example:
a=2
b=3
print(a ** b) # Output: 8

6. Swapping Lists

Unlike C++, lists can be swapped directly:


a, b = [1, 2, 3], [4, 5, 6]
a, b = b, a
print(a, b) # Output: [4, 5, 6] [1, 2, 3]

7. Functions

Use help() to get function details.


Example:
help(round)

8. Boolean Values

Example:
def can_run_for_president(age):
return age >= 35
print(can_run_for_president(19)) # Output: False

9. Lists

Lists support slicing and built-in functions like len(), sorted(), sum().

10. Loops

For and while loops help iterate over sequences.


Example:
for x in ['a', 'b', 'c']:
print(x, end=' ') # Output: a b c

11. List Comprehensions

Example:
squares = [n**2 for n in range(10)]

12. Strings

Use escaping characters and string operations like split() and join().
Example:
datestr = '1956-01-31'
year, month, day = datestr.split('-')

13. Dictionaries

Example:
numbers = {'one': 1, 'two': 2, 'three': 3}
print(numbers['one']) # Output: 1

14. External Libraries

Use math and numpy for advanced operations.


Example:
import math
print(math.pi) # Output: 3.141592653589793

You might also like