Python Forum
do not understand. can help?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
do not understand. can help?
#5
**code removed


def is the Keyword for function definition. After this come the name of the function. Then in parentheses the arguments of the function and then the colon.

Calling a function:
pint("Hello World")
print is a function.

To call print_month:
print_month("June", 30)
The last piece of code is the f-string:
text1 = "{0} has {1} days".format(month_name, num_days)
text2 = "{} has {} days".format(month_name, num_days)
text2 = "{name} has {days} days".format(name=month_name, days=num_days)
text3 = f"{month_name} has {num_days} days"

# but never do:

value1 = 42
text4 = "Something " + str(value1) + " something else."
# value1 is an int and must be converted to a str, before
# it's concatenated with "Something ". This is not very handy.
# It's also not good readable

# use instead the format method or f-strings. 
buran write Apr-08-2021, 05:04 AM:
Please, don't provide answers for those without effort on their part
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
do not understand. can help? - by Ronno - Apr-07-2021, 07:39 AM
RE: do not understand. can help? - by ndc85430 - Apr-07-2021, 07:40 AM
RE: do not understand. can help? - by ibreeden - Apr-07-2021, 10:02 AM
RE: do not understand. can help? - by deanhystad - Apr-07-2021, 11:12 AM
RE: do not understand. can help? - by DeaD_EyE - Apr-07-2021, 11:56 AM
RE: do not understand. can help? - by ndc85430 - Apr-07-2021, 03:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020