0% found this document useful (0 votes)
12 views3 pages

Python Basics: Key Functions & Concepts

The document provides a recap of Python basics, covering essential functions such as print(), input(), and len(), as well as data type conversions and string manipulation techniques. It also discusses boolean expressions, comparison operators, and the use of variables and comments in Python programming. Additionally, it includes a brief mention of arithmetic, assignment, and logical operators.

Uploaded by

Mohammad Kaif
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)
12 views3 pages

Python Basics: Key Functions & Concepts

The document provides a recap of Python basics, covering essential functions such as print(), input(), and len(), as well as data type conversions and string manipulation techniques. It also discusses boolean expressions, comparison operators, and the use of variables and comments in Python programming. Additionally, it includes a brief mention of arithmetic, assignment, and logical operators.

Uploaded by

Mohammad Kaif
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

Python Basics Recap (Automate the Boring Stuff - Unit 1)

1. print()

Displays output to the screen.

Example:

print("Hello, world!")

2. input()

Takes user input as a string.

Example:

name = input("Enter your name: ")

3. len()

Returns the number of characters/items.

Example:

len("Kaif") # 4

4. str(), int(), float()

Converts values between types.

Examples:

str(42), int('7'), float('3.14')

5. Escape Characters

\n (newline), \t (tab), \\ (backslash), \", \'

Example:

print("He said, \"Hi.\"")

6. String Concatenation & Repetition

'Hello' + 'World' -> 'HelloWorld'

'Hi' * 3 -> 'HiHiHi'


Python Basics Recap (Automate the Boring Stuff - Unit 1)

7. String Indexing & Slicing

Access parts of strings:

name[0] -> 'K'

name[1:3] -> 'ai'

8. String Methods

Useful methods:

- upper(), lower(), isalpha(), isdecimal()

- join(), split(), strip(), replace()

Example:

'-'.join(['a', 'b']) -> 'a-b'

9. Booleans & Expressions

True / False values from comparisons:

1 < 2 -> True

'hi' == 'Hi' -> False

10. Comparison Operators

==, !=, <, >, <=, >= -> used for comparisons

11. type()

Returns data type of value:

type("hello") -> <class 'str'>

12. Variables

Used to store data:

age = 18

name = "Kaif"
Python Basics Recap (Automate the Boring Stuff - Unit 1)

13. Comments

Non-executed notes:

# This is a comment

Bonus: Operators

Arithmetic: + - * / ** // %

Assignment: = += -=

Logical: and, or, not

You might also like