Computer Science
Select the correct output of the code:
s = "Python is fun"
l = s.split()
s_new = "-".join([l[0].upper(), l[1], l[2].capitalize()])
print(s_new)
- PYTHON-IS-Fun
- PYTHON-is-Fun
- Python-is-fun
- PYTHON-Is -Fun
Python String Manipulation
3 Likes
Answer
PYTHON-is-Fun
Reason — The code initializes a string variable s
with the value 'Python is fun'. It splits the string into words using split() method, then converts the first word to uppercase ('PYTHON') using indexing and the upper() method, and capitalizes the third word ('Fun') with the capitalize() method. It then joins the modified words with a hyphen ('-') as the separator using the join() method and prints the result.
Answered By
3 Likes
Related Questions
In a table in MYSQL database, an attribute A of datatype varchar(20) has the value "Keshav". The attribute B of datatype char(20) has value “Meenakshi”. How many characters are occupied by attribute A and attribute B ?
- 20, 6
- 6, 20
- 9, 6
- 6, 9
What will be the output of the following statement:
print(3 - 2 2 3 + 99/11)
- 244
- 244.0
- -244.0
- Error
In MYSQL database, if a table, Alpha has degree 5 and cardinality 3, and another table, Beta has degree 3 and cardinality 5, what will be the degree and cardinality of the Cartesian product of Alpha and Beta?
- 5, 3
- 8, 15
- 3, 5
- 15, 8
Riya wants to transfer pictures from her mobile phone to her laptop. She uses Bluetooth Technology to connect two devices. Which type of network will be formed in this case?
- PAN
- LAN
- MAN
- WAN