Python-09

/

/

/

python/09-built-in-methods

Built-In Methods in Python

Let's look at the data types that we've already covered, and focus on their functionality. All of them have certain methods available to use. So let's learn how to use it.

Python-09

/

/

/

python/09-built-in-methods

Built-In Methods in Python

Let's look at the data types that we've already covered, and focus on their functionality. All of them have certain methods available to use. So let's learn how to use it.

Lesson Objectives

  • What is a method?

  • How to use methods?

  • Learn the most important methods

Are you Ready?

Summary

Intro

Alright, let's take a step back and focus again on Data Types that you've learnt about.

I'm talking about:

  • Strings (str)

  • Integers (int)

  • Floats (float)

  • Lists (list)

  • Tuples (tuple)

  • Dictionaries (dict)

  • Sets (set)


By now you should understand the basic difference between these types, and how to create them. But you've also noticed that I used some extra functionality available to different types.

Fore Example: 'Hello {}'.format('Name') is a common method we used many times during this module. And it allows you to create placeholders in your strings and then fill them with other values. And format is a method.

Methods are like actions associated with types or classes. They provide you extra functionality. It's like a function inside of other objects that can transform, modify or create new data.


It might sound confusing for the first time, but don't worry, you will understand once we start using them.

Strings - Built-In Methods

Let's start with strings, and keep in mind that strings have more methods than any other built-in type. So don't get scared, each list will get much shorter after that one.

💡Use buttons on the top to filter between All/ Essential/Regular/Ignore methods.

String methods

All

✨Essential

Regular

❌Ignore

.capitalize()

Converts the first character to upper case

text = "Hello pyRevit Hackers."
text = text.capitalize()
print(text) # "Hello pyrevit hackers."

.casefold()

Returns a string where all the characters are lower case. Similar to .lower(), but more aggressive with international letters.

text = "Straße."
print(text.casefold()) # Output: "straße" (no change for ß)
print(text.lower())    # Output: "strasse" (ß becomes "ss")

.center()

Returns a centered string by adding spaces on each side.

text = "Hello pyRevit Hackers."
text = text.center(50)
print(text) #     Hello pyRevit Hackers.

.count()

Returns the number of times a value occurs

text    = "Hello pyRevit Hackers."
print(text.count('h')) #0
print(text.count('H')) #2

# Comment: lower and upper case letters are not equal.

.encode()

Returns an encoded version of the string

text         = "Hello pyRevit Hackers."
encoded_text = text.encode("utf-8")
print(encoded_text)

# Comment: utf-8 encoding is used for special characters like (üжÉ你حبًا)
# As a beginner, you can ignore this...

.endswith()

Returns True/False if string ends with a specific value.

text = "Hello pyRevit Hackers."
print(text.endswith('Hackers.')) #True
print(text.endswith('pyRevit'))  #False

.expandtabs()

Sets the tab size of the string

# Ignore that one...

.find()

Searches for a value and returns its position

text  = "Hello pyRevit Hackers."
print(text.find('l'))    #2
print(text.find('test')) # -1


#Comment: Only returns first match
#Comment: Returns -1 if no match

.format()

Formats specified values in a string

text = "Hello {} Hackers.".format('pyRevit')
print(text) #Hello pyRevit Hackers.

text2 ="{a}, {b}, {c}".format(a='You can also',
                             b='specify arguments',
                             c='when combining a lot of string.')
print(text2) #You can also, specify arguments, when combining a lot of string.

.format_map()

Formats specified values in a string

#❌.format_map() - Formats specified values in a string
dict_strings = {'name' : 'Erik',
                'age'  : 29 }

text = "My name is {name}, and I'm {age} years old.".format_map(dict_strings)
print(text)

.index()

Returns position of specified value

text  = "Hello pyRevit Hackers."
print(text.index('l')) #2
print(text.index('test')) # ValueError: Not found.

#Comment: Only returns first match
#Comment: Raises ValueError error if no match is found

.isalnum()

Returns True if all characters are alphanumeric

print("Hello 123".isalnum()) # False
print("Hello123".isalnum())  # True
print("Hello".isalnum())     # True
print("123".isalnum())       # True
print("!@#".isalnum())       # False

#Comment: True only if letter and numbers. Spaces are not an alpha-numeric value

.isalpha()

Returns True if all characters are in alphabet

print('abc'.isalpha())      # True 
print('abc123'.isalpha())   # False 

.isascii()

Returns True if all characters are ASCII

print('Strasse'.isascii()) #True
print('Straße'.isascii())  #False

.isdecimal()

Returns True if all characters are decimals

print('123'.isdecimal())    # True
print('123²³'.isdecimal())  # False <- Big difference to .isdigit()
print('123.50'.isdecimal()) # False
print('123,50'.isdecimal()) # False

.isdigit()

Returns True if all characters are digits

#.isdigit() - Returns True if all characters are digits
print('123'.isdigit())    # True
print('123²³'.isdigit())  # True   <- Big difference to .isdecimal()
print('123.50'.isdigit()) # False
print('123,50'.isdigit()) # False

.isidentifier()

Check is string can be used as a variable or a function name. No forbidden symbols

print("valid_identifier".isidentifier())  # True
print("1invalid".isidentifier())          # False (starts with a digit)
print("invalid!name".isidentifier())      # False (contains a special character)

.islower()

Returns True if all characters are lowercase

print('hello pyrevit hackers!'.islower()) #True
print('Hello pyRevit Hackers!'.islower()) #False

.isnumeric()

Returns True if all characters are numeric

print('123'.isnumeric())    # True
print('123²³'.isnumeric())  # True
print('123.50'.isnumeric()) # False
print('123,50'.isnumeric()) # False
print('123/2'.isnumeric())  # False

.isprintable()

Returns True if all characters are printable

print('Hello pyRevit Hackers!'.isprintable()) #True

.isspace()

Returns True if all characters are spaces

print(' '.isspace())        # True
print('      '.isspace())   # True
print('  .  '.isspace())    # False

.istitle()

Returns True if text follows title rules

print('Hello Pyrevit Hackers!'.istitle()) #True
print('Hello pyRevit Hackers!'.istitle()) #False

.isupper()

Returns True if all characters are uppercase

print('HELLO PYREVIT HACKERS!'.isupper()) #True
print('Hello pyRevit Hackers!'.isupper()) #False

.join()

Combines items from container into a string with specified separator.

items = ['A', 'B', 'C', 'D', 'E', 'F']
print("".join(items))       # ABCDEF
print(', '.join(items))     # A, B, C, D, E, F
print(" - ".join(items))    # A - B - C - D - E - F

.ljust()

Returns a left-justified version of the string

print('Hi'.ljust(10)) # Hi          (with spaces)

.lower()

Converts string to lower case

print('Hello Pyrevit Hackers!'.lower()) #hello pyrevit hackers!

.lstrip()

Removes spaces from the left side of the string

print('        Hello Pyrevit Hackers!'.lstrip()) # Hello Pyrevit Hackers!

.maketrans()

Returns a translation table as a dict.

print(str.maketrans('h', "H")) #{104: 72}

# 104: ASCII value of 'h'.
# 72: ASCII value of 'H'.
# Definetely ignore this one...

.partition()

Splits the string into 3 parts with specified value.

print('Hello Pyrevit Hackers!'.partition(" ")) # ('Hello', ' ', 'Pyrevit Hackers!')
print('Hello:World'.partition(":"))            # ('Hello', ':', 'World')

.replace()

Replaces a value with another

print('hello'.replace('l', 'L')) # heLLo
print('Hello pyRevit Hackers!'.replace("pyRevit", 'Python'))
# Hello Python Hackers

.split()

Splits the string at a specified separator

print('Hello pyRevit Hackers!'.split(" "))       # ['Hello', 'pyRevit', 'Hackers!']
print('Hello pyRevit Hackers!'.split("pyRevit")) # ['Hello ', ' Hackers!']
print('Hello pyRevit Hackers!'.split())          # ['Hello', 'pyRevit', 'Hackers!']

.startswith()

Returns True if string starts with a value

print('Hello pyRevit Hackers!'.startswith("Hello"))   # True
print('Hello pyRevit Hackers!'.startswith("pyRevit")) # False

.strip()

Removes spaces from both sides of the string

print('     Hello pyRevit Hackers!     '.strip()) #Hello pyRevit Hackers!

String methods

All

✨Essential

Regular

❌Ignore

.capitalize()

Converts the first character to upper case

text = "Hello pyRevit Hackers."
text = text.capitalize()
print(text) # "Hello pyrevit hackers."

.casefold()

Returns a string where all the characters are lower case. Similar to .lower(), but more aggressive with international letters.

text = "Straße."
print(text.casefold()) # Output: "straße" (no change for ß)
print(text.lower())    # Output: "strasse" (ß becomes "ss")

.center()

Returns a centered string by adding spaces on each side.

text = "Hello pyRevit Hackers."
text = text.center(50)
print(text) #     Hello pyRevit Hackers.

.count()

Returns the number of times a value occurs

text    = "Hello pyRevit Hackers."
print(text.count('h')) #0
print(text.count('H')) #2

# Comment: lower and upper case letters are not equal.

.encode()

Returns an encoded version of the string

text         = "Hello pyRevit Hackers."
encoded_text = text.encode("utf-8")
print(encoded_text)

# Comment: utf-8 encoding is used for special characters like (üжÉ你حبًا)
# As a beginner, you can ignore this...

.endswith()

Returns True/False if string ends with a specific value.

text = "Hello pyRevit Hackers."
print(text.endswith('Hackers.')) #True
print(text.endswith('pyRevit'))  #False

.expandtabs()

Sets the tab size of the string

# Ignore that one...

.find()

Searches for a value and returns its position

text  = "Hello pyRevit Hackers."
print(text.find('l'))    #2
print(text.find('test')) # -1


#Comment: Only returns first match
#Comment: Returns -1 if no match

.format()

Formats specified values in a string

text = "Hello {} Hackers.".format('pyRevit')
print(text) #Hello pyRevit Hackers.

text2 ="{a}, {b}, {c}".format(a='You can also',
                             b='specify arguments',
                             c='when combining a lot of string.')
print(text2) #You can also, specify arguments, when combining a lot of string.

.format_map()

Formats specified values in a string

#❌.format_map() - Formats specified values in a string
dict_strings = {'name' : 'Erik',
                'age'  : 29 }

text = "My name is {name}, and I'm {age} years old.".format_map(dict_strings)
print(text)

.index()

Returns position of specified value

text  = "Hello pyRevit Hackers."
print(text.index('l')) #2
print(text.index('test')) # ValueError: Not found.

#Comment: Only returns first match
#Comment: Raises ValueError error if no match is found

.isalnum()

Returns True if all characters are alphanumeric

print("Hello 123".isalnum()) # False
print("Hello123".isalnum())  # True
print("Hello".isalnum())     # True
print("123".isalnum())       # True
print("!@#".isalnum())       # False

#Comment: True only if letter and numbers. Spaces are not an alpha-numeric value

.isalpha()

Returns True if all characters are in alphabet

print('abc'.isalpha())      # True 
print('abc123'.isalpha())   # False 

.isascii()

Returns True if all characters are ASCII

print('Strasse'.isascii()) #True
print('Straße'.isascii())  #False

.isdecimal()

Returns True if all characters are decimals

print('123'.isdecimal())    # True
print('123²³'.isdecimal())  # False <- Big difference to .isdigit()
print('123.50'.isdecimal()) # False
print('123,50'.isdecimal()) # False

.isdigit()

Returns True if all characters are digits

#.isdigit() - Returns True if all characters are digits
print('123'.isdigit())    # True
print('123²³'.isdigit())  # True   <- Big difference to .isdecimal()
print('123.50'.isdigit()) # False
print('123,50'.isdigit()) # False

.isidentifier()

Check is string can be used as a variable or a function name. No forbidden symbols

print("valid_identifier".isidentifier())  # True
print("1invalid".isidentifier())          # False (starts with a digit)
print("invalid!name".isidentifier())      # False (contains a special character)

.islower()

Returns True if all characters are lowercase

print('hello pyrevit hackers!'.islower()) #True
print('Hello pyRevit Hackers!'.islower()) #False

.isnumeric()

Returns True if all characters are numeric

print('123'.isnumeric())    # True
print('123²³'.isnumeric())  # True
print('123.50'.isnumeric()) # False
print('123,50'.isnumeric()) # False
print('123/2'.isnumeric())  # False

.isprintable()

Returns True if all characters are printable

print('Hello pyRevit Hackers!'.isprintable()) #True

.isspace()

Returns True if all characters are spaces

print(' '.isspace())        # True
print('      '.isspace())   # True
print('  .  '.isspace())    # False

.istitle()

Returns True if text follows title rules

print('Hello Pyrevit Hackers!'.istitle()) #True
print('Hello pyRevit Hackers!'.istitle()) #False

.isupper()

Returns True if all characters are uppercase

print('HELLO PYREVIT HACKERS!'.isupper()) #True
print('Hello pyRevit Hackers!'.isupper()) #False

.join()

Combines items from container into a string with specified separator.

items = ['A', 'B', 'C', 'D', 'E', 'F']
print("".join(items))       # ABCDEF
print(', '.join(items))     # A, B, C, D, E, F
print(" - ".join(items))    # A - B - C - D - E - F

.ljust()

Returns a left-justified version of the string

print('Hi'.ljust(10)) # Hi          (with spaces)

.lower()

Converts string to lower case

print('Hello Pyrevit Hackers!'.lower()) #hello pyrevit hackers!

.lstrip()

Removes spaces from the left side of the string

print('        Hello Pyrevit Hackers!'.lstrip()) # Hello Pyrevit Hackers!

.maketrans()

Returns a translation table as a dict.

print(str.maketrans('h', "H")) #{104: 72}

# 104: ASCII value of 'h'.
# 72: ASCII value of 'H'.
# Definetely ignore this one...

.partition()

Splits the string into 3 parts with specified value.

print('Hello Pyrevit Hackers!'.partition(" ")) # ('Hello', ' ', 'Pyrevit Hackers!')
print('Hello:World'.partition(":"))            # ('Hello', ':', 'World')

.replace()

Replaces a value with another

print('hello'.replace('l', 'L')) # heLLo
print('Hello pyRevit Hackers!'.replace("pyRevit", 'Python'))
# Hello Python Hackers

.split()

Splits the string at a specified separator

print('Hello pyRevit Hackers!'.split(" "))       # ['Hello', 'pyRevit', 'Hackers!']
print('Hello pyRevit Hackers!'.split("pyRevit")) # ['Hello ', ' Hackers!']
print('Hello pyRevit Hackers!'.split())          # ['Hello', 'pyRevit', 'Hackers!']

.startswith()

Returns True if string starts with a value

print('Hello pyRevit Hackers!'.startswith("Hello"))   # True
print('Hello pyRevit Hackers!'.startswith("pyRevit")) # False

.strip()

Removes spaces from both sides of the string

print('     Hello pyRevit Hackers!     '.strip()) #Hello pyRevit Hackers!
List - Built-In Methods

Next are lists. There are much less methods here, but they are more important than strings in my opinion. So, make sure to pay more attention to all essential methods here.

List methods

All

✨Essential

Regular

.append()

Adds an element at the end of the list

my_list = [1, 2]
my_list.append(3)
print(my_list) # [1,2,3]

.copy()

Returns a copy of the list

my_list = [1, 2]
new_list = my_list.copy()

.count()

Returns the number of elements with the specified value

my_list   = [1, 2, 1]
one_count = my_list.count(1)
print(one_count) # 2

.extend()

Adds all elements of an iterable to the end of the list

list_1 = [1,2]
list_2 = [3,4]
list_1.extend(list_2)
print(list_1) # [1,2,3,4]

# Better Alternative:
list_3 = list_1 + list_2
print(list_3) #[1,2,3,4]

.index()

Returns the index of the first element with the specified value

my_list = [1, 2, 3]
idx     = my_list.index(2)
print(idx) #1 (remember, in python we count from 0)

.insert()

Adds an element at the specified position

my_list = [1, 3]
my_list.insert(1, 2)
print(my_list) #[1, 2, 3]

.pop()

Removes the element at the specified index and returns it

my_list = [1, 2, 3]
item    = my_list.pop(1)

print(item)    # 3
print(my_list) # [1,2]

# Comment: By default, removes the last element. 
# You can also specify what item to pop

.remove()

Removes the item with the specified value

my_list = [1, 2, 3]
my_list.remove(2)
print(my_list) #[1, 3]

# Comment: Throws an error if the value doesn’t exist.

.reverse()

Reverses the order of the list

my_list = [1, 2, 3]
my_list.reverse()

.sort()

Sorts the list in ascending order

my_list = [3, 1, 2]
my_list.sort()              # Updates existing list.
print(my_list) [1,2,3]

#Comment: Use sorted(my_list) to get a sorted copy without changing the original list.

clear()

Removes all the elements from the list

my_list = [1, 2]
my_list.clear()
print(my_list) #[]

List methods

All

✨Essential

Regular

.append()

Adds an element at the end of the list

my_list = [1, 2]
my_list.append(3)
print(my_list) # [1,2,3]

.copy()

Returns a copy of the list

my_list = [1, 2]
new_list = my_list.copy()

.count()

Returns the number of elements with the specified value

my_list   = [1, 2, 1]
one_count = my_list.count(1)
print(one_count) # 2

.extend()

Adds all elements of an iterable to the end of the list

list_1 = [1,2]
list_2 = [3,4]
list_1.extend(list_2)
print(list_1) # [1,2,3,4]

# Better Alternative:
list_3 = list_1 + list_2
print(list_3) #[1,2,3,4]

.index()

Returns the index of the first element with the specified value

my_list = [1, 2, 3]
idx     = my_list.index(2)
print(idx) #1 (remember, in python we count from 0)

.insert()

Adds an element at the specified position

my_list = [1, 3]
my_list.insert(1, 2)
print(my_list) #[1, 2, 3]

.pop()

Removes the element at the specified index and returns it

my_list = [1, 2, 3]
item    = my_list.pop(1)

print(item)    # 3
print(my_list) # [1,2]

# Comment: By default, removes the last element. 
# You can also specify what item to pop

.remove()

Removes the item with the specified value

my_list = [1, 2, 3]
my_list.remove(2)
print(my_list) #[1, 3]

# Comment: Throws an error if the value doesn’t exist.

.reverse()

Reverses the order of the list

my_list = [1, 2, 3]
my_list.reverse()

.sort()

Sorts the list in ascending order

my_list = [3, 1, 2]
my_list.sort()              # Updates existing list.
print(my_list) [1,2,3]

#Comment: Use sorted(my_list) to get a sorted copy without changing the original list.

clear()

Removes all the elements from the list

my_list = [1, 2]
my_list.clear()
print(my_list) #[]
Tuple - Built-In Methods

Tuples only have 2 methods, and they aren't so exciting either.

Remember, tuples are very limited objects to store data and be as fast as they could.

Tuple methods

All

.count()

Returns the number of times a specified value occurs in the tuple

my_tuple = (1, 2, 1)
my_tuple.count(1) 
print(my_tuple) #2

.index()

Returns the index of the first occurrence of the specified value

my_tuple = (1, 2, 3)
my_tuple.index(2) 
print(my_tuple) #1
# Comment: Count starts with 0 in programming
# Comment: Throws an error if the value isn’t in the tuple.

Tuple methods

All

.count()

Returns the number of times a specified value occurs in the tuple

my_tuple = (1, 2, 1)
my_tuple.count(1) 
print(my_tuple) #2

.index()

Returns the index of the first occurrence of the specified value

my_tuple = (1, 2, 3)
my_tuple.index(2) 
print(my_tuple) #1
# Comment: Count starts with 0 in programming
# Comment: Throws an error if the value isn’t in the tuple.
Dictionary - Built-In Methods

Alright, and finally we are getting to dictionaries.

There are a few very essential methods you have to learn, but overall it's not so complicated once you understand dictionaries themselves.

Dictionary methods

All

✨Essential

Regular

.clear()

Removes all the elements from the dictionary

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
my_dict.clear()

print(my_dict) #{}

.copy()

Returns a copy of the dictionary

my_dict = {"a": 1,
           "b": 2,
           "c": 3}

new_dict = my_dict.copy()
print(new_dict) # {"a": 1, "b": 2, "c": 3}

.fromkeys()

Returns a dictionary with the specified keys and value

keys     = ["a", "b", "c"]
new_dict = dict.fromkeys(keys, 0)
print(new_dict) # {"a": 0, "b": 0, "c": 0}

.get()

Returns the value of the specified key

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
value = my_dict.get("a")
print(value) # 1

# Better Way:
alternative = my_dict["a"]

.items()

Returns a list of tuples with key-value pairs

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
items = my_dict.items()
print(items) # [ ("a": 1), ("b": 2), ("c": 3) ]

.keys()

Returns a list of all the dictionary's keys

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
keys = my_dict.keys()
print(keys) # ["a", "b", "c"]

.pop()

Removes the element with the specified key

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
value = my_dict.pop("a")

print(value)   # 1
print(my_dict) #{"b": 2, "c": 3}

.popitem()

Removes the last inserted key-value pair

my_dict = {"a": 1, "b": 2, "c": 3}
item    = my_dict.popitem()

print(item)   # ("c", 3)
print(my_dict) # {"a": 1, "b": 2}

.setdefault()

Returns the value of the specified key, and adds it if it doesn’t exist

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
value_c = my_dict.setdefault("c", 4) # {'a': 1, 'b': 2, 'c': 3}
value_d = my_dict.setdefault("d", 4) # {'a': 1, 'b': 2, 'c': 3, 'd': 4}

print(value_c) # 3
print(value_d) # 4

.update()

Updates the dictionary with another dictionary. (add 2 together + override)

my_dict_1 = {"a": 1,
             "b": 2,
             "c": 3}

my_dict_2 = {"d": 4,
             "e": 5,
             "f": 6}

my_dict_1.update(my_dict_2)

print(my_dict_1) # {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6}

.values()

Returns a list of all the values in the dictionary

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
values = my_dict.values()
print(values) #[1,2,3]

Dictionary methods

All

✨Essential

Regular

.clear()

Removes all the elements from the dictionary

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
my_dict.clear()

print(my_dict) #{}

.copy()

Returns a copy of the dictionary

my_dict = {"a": 1,
           "b": 2,
           "c": 3}

new_dict = my_dict.copy()
print(new_dict) # {"a": 1, "b": 2, "c": 3}

.fromkeys()

Returns a dictionary with the specified keys and value

keys     = ["a", "b", "c"]
new_dict = dict.fromkeys(keys, 0)
print(new_dict) # {"a": 0, "b": 0, "c": 0}

.get()

Returns the value of the specified key

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
value = my_dict.get("a")
print(value) # 1

# Better Way:
alternative = my_dict["a"]

.items()

Returns a list of tuples with key-value pairs

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
items = my_dict.items()
print(items) # [ ("a": 1), ("b": 2), ("c": 3) ]

.keys()

Returns a list of all the dictionary's keys

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
keys = my_dict.keys()
print(keys) # ["a", "b", "c"]

.pop()

Removes the element with the specified key

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
value = my_dict.pop("a")

print(value)   # 1
print(my_dict) #{"b": 2, "c": 3}

.popitem()

Removes the last inserted key-value pair

my_dict = {"a": 1, "b": 2, "c": 3}
item    = my_dict.popitem()

print(item)   # ("c", 3)
print(my_dict) # {"a": 1, "b": 2}

.setdefault()

Returns the value of the specified key, and adds it if it doesn’t exist

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
value_c = my_dict.setdefault("c", 4) # {'a': 1, 'b': 2, 'c': 3}
value_d = my_dict.setdefault("d", 4) # {'a': 1, 'b': 2, 'c': 3, 'd': 4}

print(value_c) # 3
print(value_d) # 4

.update()

Updates the dictionary with another dictionary. (add 2 together + override)

my_dict_1 = {"a": 1,
             "b": 2,
             "c": 3}

my_dict_2 = {"d": 4,
             "e": 5,
             "f": 6}

my_dict_1.update(my_dict_2)

print(my_dict_1) # {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6}

.values()

Returns a list of all the values in the dictionary

my_dict = {"a": 1,
           "b": 2,
           "c": 3}
values = my_dict.values()
print(values) #[1,2,3]

HomeWork

For this lesson I want you to go over the most essential methods so you learn what is available. And you can always find out how to use it in your code with a simple search or ChatGPT question.

It might look like an endless list, but it's not.
In total there are 57 Built-In Methods:

  • 26 Essential (in my opinion)

  • 22 Regular

  • 9 Ignore

Majority of them are self-explanatory and very easy to use.
And I've made sure there are code examples you can copy-paste to see how it works.

Explore python methods.

⌨️ Happy Coding!

Questions:

Should I learn all methods?

Should I learn all methods?

Who defined them as Essential Methods

Who defined them as Essential Methods

Discuss the lesson :

P.S. Sometimes this chat might experience connection issues.

Use Discord App for best experience.

Discuss the lesson :

P.S. Sometimes this chat might experience connection issues.

Use Discord App for best experience.

Discuss the lesson :

P.S. Sometimes this chat might experience connection issues.

Use Discord App for best experience.

Unlock Community

The pyRevit Hackers Community is only available with pyRevit Hackers Bundle.
Upgrade Here to Get Access to the community and all pyRevit Courses.

Use coupon code "upgrade" to get 150EUR Discount as a member.

⌨️ Happy Coding!

Unlock Community

The pyRevit Hackers Community is only available with pyRevit Hackers Bundle.
Upgrade Here to Get Access to the community and all pyRevit Courses.

Use coupon code "upgrade" to get 150EUR Discount as a member.

⌨️ Happy Coding!

Unlock Community

The pyRevit Hackers Community is only available with pyRevit Hackers Bundle.
Upgrade Here to Get Access to the community and all pyRevit Courses.

Use coupon code "upgrade" to get 150EUR Discount as a member.

⌨️ Happy Coding!

© 2023-2024 EF Learn Revit API

© 2023-2024 EF Learn Revit API

© 2023-2024 EF Learn Revit API