Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion first_class_19_apr/Assigment.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
# Assigments:
- Research and list the rules for naming variables in Python.
- Answer: 1. Start with a letter or underscore: Variable names must begin with a letter (A-Z, a-z) or an underscore (_), but not a number.
2. No spaces: Variable names cannot contain spaces. Use underscores (_) to separate words if needed.
3. Only alphanumeric characters and underscores: Variable names can include letters, numbers (0-9), and underscores (_), but no special characters like @, $, or %.
4. Case-sensitive: Python treats uppercase and lowercase letters as different variables. For example, name, Name, and NAME are three distinct variables.
5. Cannot be a Python keyword: You cannot use reserved words like class, def, return, or import as variable names.
6. Use meaningful names: While not a strict rule, it's best practice to use descriptive names like student_id instead of sid or x.
7. Follow naming conventions:
o Camel Case: myVariableName
o Pascal Case: MyVariableName
o Snake Case: my_variable_name
- Explore the precedence of arithmetic operators in Python.
- Answer: 1. Parentheses () – Highest precedence; operations inside parentheses are evaluated first.
2. Exponentiation ** – Right-to-left associativity (e.g., 2 ** 3 ** 2 evaluates as 2 ** (3 ** 2)).
3. Unary operators +x, -x, ~x – Unary plus, minus, and bitwise NOT.
4. Multiplication, Division, Floor Division, Modulus *, /, //, % – Left-to-right associativity.
5. Addition and Subtraction +, - – Left-to-right associativity.
6. Bitwise Shift Operators <<, >> – Left-to-right associativity.
7. Bitwise AND & – Left-to-right associativity.
8. Bitwise XOR ^ – Left-to-right associativity.
9. Bitwise OR | – Left-to-right associativity.
- Explore all string methods in Python.

- Answer: String Modification Methods
• capitalize() – Converts the first character to uppercase.
• lower() – Converts all characters to lowercase.
• upper() – Converts all characters to uppercase.
• title() – Converts the first character of each word to uppercase.
• swapcase() – Swaps uppercase and lowercase characters.
String Checking Methods
• isalnum() – Returns True if all characters are alphanumeric.
• isalpha() – Returns True if all characters are alphabetic.
• isdigit() – Returns True if all characters are digits.
• isspace() – Returns True if all characters are whitespace.
• isupper() – Returns True if all characters are uppercase.
• islower() – Returns True if all characters are lowercase.
String Searching Methods
• find(substring) – Returns the index of the first occurrence of substring, or -1 if not found.
• index(substring) – Similar to find(), but raises an error if substring is not found.
• count(substring) – Returns the number of occurrences of substring.
• startswith(prefix) – Returns True if the string starts with prefix.
• endswith(suffix) – Returns True if the string ends with suffix.
String Modification & Formatting
• replace(old, new) – Replaces occurrences of old with new.
• strip() – Removes leading and trailing whitespace.
• lstrip() – Removes leading whitespace.
• rstrip() – Removes trailing whitespace.
• split(separator) – Splits the string into a list based on separator.
• join(iterable) – Joins elements of an iterable into a string.
String Alignment Methods
• center(width) – Centers the string within a given width.
• ljust(width) – Left-aligns the string within a given width.
• rjust(width) – Right-aligns the string within a given width.
String Encoding & Translation
• encode(encoding) – Encodes the string using the specified encoding.
• translate(mapping) – Translates characters using a mapping table.
-----------


Expand Down