Created
March 19, 2020 08:02
-
-
Save xb4dc0d3/da23bbd7fa8da2d14e0d1a886697c2db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bad | |
name = "Cristiano Rolando" | |
def split_into_first_and_last_name(): | |
global name | |
name = name.split() | |
# ketika fungsi dieksusi akan merusak dari global variabel name | |
split_into_first_and_last_name() | |
print(name) | |
# Good | |
def split_into_first_and_last_name(name): | |
return name.split() | |
name = "Cristiano Rolando" | |
# ketika fungi dieksekusi tidak akan merusak variabel name awal, karena di passing dengan argumen | |
first_name, last_name = split_into_first_and_last_name(name) | |
print(first_name, last_name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment