Forwarded from Python Courses
⭐️ Tags:
#PythonCheatSheet #PythonProgramming #DataScience #CodingTips #Python3 #LearnPython #ProgrammingGuide #PythonSyntax #CodeSnippets #DataStructures #OOP #Regex #ErrorHandling #PythonLibraries #CodingReference #PythonTricks #TechResources #DeveloperTools #PythonForBeginners #AdvancedPython
Please open Telegram to view this post
VIEW IN TELEGRAM
👍4🔥1
#37.
Returns
#38.
Returns
#39.
Searches the string for a specified value and returns the position of where it was found. Returns -1 if not found.
#40.
A way to embed expressions inside string literals.
---
#Python #ListMethods #DataStructures
#41.
Adds an element at the end of the list.
#42.
Removes the element at the specified position.
#43.
Removes the first item with the specified value.
#44.
Adds an element at the specified position.
#45.
Sorts the list in place.
---
#Python #DictionaryMethods #DataStructures
#46.
Creates a dictionary.
#47.
Returns a view object displaying a list of all the keys in the dictionary.
#48.
Returns a view object displaying a list of all the values in the dictionary.
#49.
Returns a view object displaying a list of a given dictionary's key-value tuple pairs.
#50.
Returns the value of the specified key. Provides a default value if the key does not exist.
---
#Python #ErrorHandling #FileIO
#51.
Used to handle errors and exceptions.
.startswith()Returns
True if the string starts with the specified value.filename = "document.pdf"
print(filename.startswith("doc"))
True
#38.
.endswith()Returns
True if the string ends with the specified value.filename = "image.jpg"
print(filename.endswith(".jpg"))
True
#39.
.find()Searches the string for a specified value and returns the position of where it was found. Returns -1 if not found.
text = "hello world"
print(text.find("world"))
6
#40.
f-string (Formatted String Literal)A way to embed expressions inside string literals.
name = "Alice"
age = 30
print(f"{name} is {age} years old.")
Alice is 30 years old.
---
#Python #ListMethods #DataStructures
#41.
.append()Adds an element at the end of the list.
fruits = ['apple', 'banana']
fruits.append('cherry')
print(fruits)
['apple', 'banana', 'cherry']
#42.
.pop()Removes the element at the specified position.
fruits = ['apple', 'banana', 'cherry']
fruits.pop(1) # Removes 'banana'
print(fruits)
['apple', 'cherry']
#43.
.remove()Removes the first item with the specified value.
fruits = ['apple', 'banana', 'cherry', 'banana']
fruits.remove('banana')
print(fruits)
['apple', 'cherry', 'banana']
#44.
.insert()Adds an element at the specified position.
fruits = ['apple', 'cherry']
fruits.insert(1, 'banana')
print(fruits)
['apple', 'banana', 'cherry']
#45.
.sort()Sorts the list in place.
numbers = [3, 1, 5, 2]
numbers.sort()
print(numbers)
[1, 2, 3, 5]
---
#Python #DictionaryMethods #DataStructures
#46.
dict()Creates a dictionary.
my_dict = dict(name="John", age=36)
print(my_dict)
{'name': 'John', 'age': 36}#47.
.keys()Returns a view object displaying a list of all the keys in the dictionary.
person = {'name': 'Alice', 'age': 25}
print(person.keys())dict_keys(['name', 'age'])
#48.
.values()Returns a view object displaying a list of all the values in the dictionary.
person = {'name': 'Alice', 'age': 25}
print(person.values())dict_values(['Alice', 25])
#49.
.items()Returns a view object displaying a list of a given dictionary's key-value tuple pairs.
person = {'name': 'Alice', 'age': 25}
print(person.items())dict_items([('name', 'Alice'), ('age', 25)])#50.
.get()Returns the value of the specified key. Provides a default value if the key does not exist.
person = {'name': 'Alice', 'age': 25}
print(person.get('city', 'Unknown'))Unknown
---
#Python #ErrorHandling #FileIO
#51.
try, exceptUsed to handle errors and exceptions.