Quick actions

cmd+k|ctrl+k

Navigation

Languages

Basics 19/01 - Functions + methods

Snippet info

Language

Python

Visibility

public

Author

jjohn73

Created

2026-01-19T15:01:23.555061Z

Updated

2026-01-19T15:01:23.555061Z

#print(len('goooooon')) #prints the length of a string, doesn't start as 0 like indexes 
# greet = 'helloooooooo'
# print(greet[0:len(greet)]) # this will print the full variable as length of greet

# # methods are similar to functions e.g. .format() is a method for strings

# quote = 'to goon or not to goon'

# print(quote.upper()) # capitalizes whole string into upper case
# print(quote.capitalize()) # capitalizes just the start of the text
# print(quote.find('goon')) #finds first occurence of a piece of text, here it returns 3
# print(quote.replace('goon', 'me')) # replaces all instances of first w/ second
# print(quote) # as strings are immutable, this will return the original quote regardless of above changes

# #Booleans

# #bool #can only be true or false

# name = 'goop'
# is_cool = False

# is_cool = True

# print(bool(1))# 1 is true, 0 is false

#Type conversion Exercise

# name = 'goop gooperson'
# age = 73
# relationship_status = 'single'

# relationship_status = 'it\'s complicated'

# # print(relationship_status) # somewhat clunky way to reassign status

# birth_year = input('what year were you born? ')

# age = 2026 - int(birth_year) # int to convert the string from  input into an int for calculation

# print(f'your age is: {age}') # f to format the entire output as a string

# Password Checker Exercise

# username = input('what is your username? ')
# password = input('what is your password? ')

# passwordlength = len(password) #int was not needed here, removed
# hiddenpass = '*' * passwordlength # ok i actually did everything correctly based

# print(f'{username}, your password {hiddenpass} is {passwordlength} letters long')



INFO