FUNDAMENTALS OF PROGRAMMING IN PYTHON

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/31

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

32 Terms

1
New cards

1. DATA TYPES IN PYTHON

- Python has several built-in data types, categorized as follows:

2
New cards

int

A) NUMERIC TYPES

– Whole numbers (e.g., 10, -3, 1000)

3
New cards

float

A) NUMERIC TYPES

– Decimal numbers (e.g., 3.14, -0.001, 2.0)

4
New cards

complex

A) NUMERIC TYPES

– Numbers with real and imaginary parts (e.g., 3 + 4j)

5
New cards

str

B) SEQUENCE TYPES

– String (e.g., "Hello, World!")

6
New cards

list

B) SEQUENCE TYPES

– Ordered, mutable collection (e.g., [1, 2, 3, "hello"])

7
New cards

tuple

B) SEQUENCE TYPES

– Ordered, immutable collection (e.g., (10, 20, 30))

8
New cards

range

B) SEQUENCE TYPES

– Sequence of numbers (e.g., range(5) → 0, 1, 2, 3, 4)

9
New cards

set

C) SET TYPES

– Unordered collection of unique items (e.g., {1, 2, 3, 4})

10
New cards

frozenset

C) SET TYPES

– Immutable version of a set

11
New cards

dict

D) MAPPING TYPE

– Key-value pairs (e.g., {"name": "Alice", "age": 25})

12
New cards

bool

E) BOOLEAN TYPE

– Logical values (True, False)

13
New cards

None

F) NONE TYPE

– Represents a null value

14
New cards

2. OPERATORS IN PYTHON

- Python has various operators to perform operations

15
New cards

ARITHMETIC OPERATORS

+ (Addition) → 3 + 2 = 5

- (Subtraction) → 7 - 4 = 3

* (Multiplication) → 5 2 = 10

/ (Division) → 10 / 2 = 5.0

// (Floor Division) → 10 // 3 = 3

% (Modulus) → 10 % 3 = 1

(Exponentiation) → 2 3 = 8

16
New cards

COMPARISON OPERATORS

• == (Equal to)

• != (Not equal to)

• > (Greater than)

• < (Less than)

• >= (Greater than or equal to)

• <= (Less than or equal to)

17
New cards

and

C) LOGICAL OPERATORS

(Both conditions must be true)

18
New cards

or

C) LOGICAL OPERATORS

(At least one condition must be true)

19
New cards

not

C) LOGICAL OPERATORS

(Reverses the Boolean value)

20
New cards

BITWISE OPERATORS

• & (AND)

• | (OR)

• ^ (XOR)

• ~ (NOT)

• << (Left Shift)

• >> (Right Shift)

21
New cards

in, not in

F) MEMBERSHIP AND IDENTITY OPERATORS

(Check membership in a sequence)

22
New cards

is, is not

F) MEMBERSHIP AND IDENTITY OPERATORS

(Check object identity)

23
New cards

INPUT STATEMENTS

• Used to take user input

input() always returns a string

• Example:

name = input("Enter your name: ")

age = int(input("Enter your age: ")) # Convert string to int

print(f"Hello, {name}. You are {age} years old.")

24
New cards

OUTPUT STATEMENTS

print() is used to display output

• Example:

print("Hello, World!")

print("The sum is:", 10 + 5)

print(f"The sum of {10} and {5} is {10 + 5}") # f-string

25
New cards

IF STATEMENT

• Executes a block of code only if a condition is true

• Example:

num = int(input("Enter a number: "))

if num > 0:

print("Positive number")

26
New cards

IF-ELSE STATEMENT

• Provides an alternative block of code if the condition is false

• Example:

num = int(input("Enter a number: "))

if num > 0:

print("Positive number")

else:

print("Non-positive number")

27
New cards

IF-ELIF-ELSE STATEMENT

• Allows multiple conditions to be checked sequentially

• Example:

num = int(input("Enter a number: "))

if num > 0:

print("Positive number")

elif num < 0:

print("Negative number")

else:

print("Zero")

28
New cards

FOR LOOP

• Used to iterate over sequences

• Example:

for i in range(5):

print(i) # Prints 0 to 4

29
New cards

WHILE LOOP

• Repeats a block of code as long as a condition is true

• Example:

num = 5

while num > 0:

print(num)

num -= 1 # Decrease num by 1

30
New cards

break

C) LOOP CONTROL STATEMENTS

– Exits the loop

Example:

for i in range(10): if i == 5:

break # Stops the loop when i is 5

print(i)

31
New cards

continue

C) LOOP CONTROL STATEMENTS

– Skips the current iteration and moves to the next

Example:

for i in range(10):

if i % 2 == 0:

continue # Skips even numbers print(i)

32
New cards

pass

C) LOOP CONTROL STATEMENTS

– Placeholder for future code