Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 I'm trying to figure out whether this is a method or function call
I'm doing some simple string formatting examples in Python and I'm using the old style C method for an example in my program. I understand that when you type %s within your string that is simple a placeholder for where your data or argument is going to go.

But what I don't understand is when you type the final % right before your arguments in parentheses, is that actually a method or a function call? When people were doing C language did they learn that as a call to a function?

Here is my code:

subject = "Engineering"
language = "Python"

print("I am studying %s and using %s as the programming language" % (subject, language))
Don't use this old method anymore.
f-string is what you should use,was new in Python 3.6(2-year ago).
subject = "Engineering"
language = "Python"

print(f"I am studying {subject} and using {language} as the programming language")
I am studying Engineering and using Python as the programming language
11 year ago in 2.6 foramt() was new.
subject = "Engineering"
language = "Python"

print("I am studying {} and using {} as the programming language".format(subject, language))
I am studying Engineering and using Python as the programming language
Not only are f-string far more readable more concise,and less prone to error than other ways of formatting,but they are also faster!
>>> name = 'f-string'
>>> print(f"String formatting is called {name.upper():*^20}")
String formatting is called ******F-STRING******

# f-strings can take any Python expressions inside the curly braces.
>>> cost = 99.75999
>>> finance = 50000
>>> print(f'Toltal cost {cost + finance:.2f}')
Toltal cost 50099.76

>>> for word in 'f-strings are cool'.split():
...     print(f'{word.upper():~^20}')
To answer the original question, it's neither. It's an operator.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Accessing method as function object ClassicalSoul 2 119 Feb-14-2020, 09:31 PM
Last Post: wavic
  How to mock an object that is created during function call? Schlangenversteher 0 129 Jan-31-2020, 01:36 PM
Last Post: Schlangenversteher
  Is there a way to search for function call? mtran 2 105 Jan-14-2020, 02:07 AM
Last Post: mtran
  what would you call the input for the parameter(s) of a function you have defined? rix 3 155 Dec-16-2019, 12:04 AM
Last Post: rix
  Call to a print in a defined function leodavinci1990 1 120 Nov-20-2019, 01:45 AM
Last Post: ichabod801
  How to call COM-method using comtypes jespersahner 0 112 Nov-15-2019, 12:54 PM
Last Post: jespersahner
  function vs method prateekshaw 2 160 Nov-14-2019, 07:00 PM
Last Post: DeaD_EyE
  Polymorphism not working with a call to a abstract method colt 3 180 Nov-04-2019, 11:04 PM
Last Post: colt
  How to Call a method of class having no argument dataplumber 7 514 Oct-31-2019, 01:52 PM
Last Post: dataplumber
  How can I call a c++ function using python HWDev 1 212 Oct-22-2019, 06:19 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)