206k views
4 votes
What is the output from this print() function call: print( '$100 $200 $300'.count('$'), '$100 $200 $300'.count('$', 5, 10), '$100 $200 $300'.count('$', 5) )

1 Answer

2 votes

The count() function compares the number of units with the value specified. so, the complete Python program and its description can be defined as follows:

Program Explanation:

In this program, a string type variable "t" is declared that holds a value that is "$100 $200 $300".

After accepting a value three print method is declared that uses the count methods.

In the first method, it counts how many times "$" comes.

In the second method, it counts how many times "s" comes, but in this, it uses another variable that is "5" which counts value after 5th position.

In the third method, it counts how many times "$" comes, but in this, it uses two other variables that are "5, 10" which counts value after the 5th and before 10th position.

Program:

t = "$100 $200 $300"#defining a string type variable t that holds a vlue

print(t.count('$'))#using print method that calls count method and prints its value

print(t.count('s', 5))#using print method that calls count method and prints its value

print(t.count('$', 5, 10))#using print method that calls count method and prints its value

User Acj
by
6.9k points