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
#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))
Quote
#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~~~~~~~~
Quote
#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

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Bound method Uchikago 1 136 Jul-26-2019, 04:43 PM
Last Post: Gribouillis
  What is the use of call method and when to use it? everyday1 1 116 Jul-14-2019, 01:02 PM
Last Post: ichabod801
  Method not defined diskt 1 177 Jul-03-2019, 12:55 PM
Last Post: noisefloor
  API Call Gets 404 Error jimbone30 0 151 Jun-28-2019, 04:06 AM
Last Post: jimbone30
  call func from dict mcmxl22 3 306 Jun-21-2019, 05:20 AM
Last Post: snippsat
  Method not regocnized Lass86 3 243 Jun-19-2019, 09:03 AM
Last Post: Lass86
  API call returning list value of 'None' jimbone30 5 299 Jun-14-2019, 07:42 PM
Last Post: jimbone30
  Call a Function contained in a Tuple SamGer 7 355 Jun-14-2019, 05:00 PM
Last Post: ThomasL
  variable call back into an array yamifm0f 3 257 Jun-07-2019, 02:44 PM
Last Post: heiner55
  web3 method rembrandt 3 214 Jun-04-2019, 05:43 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)