Python Forum
I'm trying to figure out whether this is a method or function call
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
#1
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))
Reply
#2
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")
Output:
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))
Output:
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}')
...
~~~~~F-STRINGS~~~~~~
~~~~~~~~ARE~~~~~~~~~
~~~~~~~~COOL~~~~~~~~
Reply
#3
To answer the original question, it's neither. It's an operator.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 752 May-02-2023, 08:40 AM
Last Post: Gribouillis
  method call help sollarriiii 6 1,078 Feb-21-2023, 03:19 AM
Last Post: noisefloor
  i want to use type= as a function/method keyword argument Skaperen 9 1,775 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  how to call an object in another function in Maya bstout 0 2,042 Apr-05-2021, 07:12 PM
Last Post: bstout
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 3,417 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,158 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,862 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  Building a method name in a function ffgth 9 3,132 Oct-19-2020, 01:21 PM
Last Post: buran
  function call at defined system time? Holon 5 3,155 Oct-06-2020, 03:58 PM
Last Post: snippsat
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,039 Jul-27-2020, 04:19 PM
Last Post: buran

Forum Jump:

User Panel Messages

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