Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Suppose I have two variables that are called animal and age, and print them as a string in the console like so: animal = "giraffe" age = 25 print("A %s can live up to %d years" %(animal,age)) ...
#4: Post edited
Why are commas not needed for modulo string formatting when printing?
I have a question about format specifiers.For example:I have two variables that are called `animal` and `age`, and print them as a string in the console using format specifiers. Why do we place the modulo operator `%(animal,age)` next to the string without a comma? Does Python automatically detect that it needs two parameters to execute?Here is the code example:- ```
- animal = "giraffe"
- age = 25
- print("A %s can live up to %d years" %(animal,age))
```
- Suppose I have two variables that are called `animal` and `age`, and print them as a string in the console like so:
- ```
- animal = "giraffe"
- age = 25
- print("A %s can live up to %d years" %(animal,age))
- ```
- Why shouldn't there be a comma between the string and the `%(animal,age)` part? Does Python automatically detect that it needs two parameters to execute?
#3: Post edited
Why are commas not needed for modulo string formatting when printing?
I'm still a novice in Python. But have come across a question about format specifiers. For example, if I have two variables that are called `animal` and `age`. And print a string in the console using format specifiers. Why do we place the modulo operator `%(animal,age)` next to the string without a comma? Does Python automatically detect that it needs two parameters to execute?- Here is the code example:
- ```
- animal = "giraffe"
- age = 25
- print("A %s can live up to %d years" %(animal,age))
- ```
- I have a question about format specifiers.
- For example:
- I have two variables that are called `animal` and `age`, and print them as a string in the console using format specifiers. Why do we place the modulo operator `%(animal,age)` next to the string without a comma? Does Python automatically detect that it needs two parameters to execute?
- Here is the code example:
- ```
- animal = "giraffe"
- age = 25
- print("A %s can live up to %d years" %(animal,age))
- ```
#1: Initial revision
Why are commas not needed for modulo string formatting when printing?
I'm still a novice in Python. But have come across a question about format specifiers. For example, if I have two variables that are called `animal` and `age`. And print a string in the console using format specifiers. Why do we place the modulo operator `%(animal,age)` next to the string without a comma? Does Python automatically detect that it needs two parameters to execute? Here is the code example: ``` animal = "giraffe" age = 25 print("A %s can live up to %d years" %(animal,age)) ```