kiếm chỗ ghi vài thứ thôi

sallynhung

Thành viên
Tham gia
25/11/2021
Bài viết
1

str : tuple ( ) , dict ( )


- Return the string without any whitespace at the beginning or the end

x = txt.strip()


- Replace the character H with a J.
txt = "Hello World"​


txt = txt.replace("H", "J" )


- Insert the correct syntax to add a placeholder for the age parameter.
age = 36
txt = "My name is John, and I am { }"

print(txt.format(age))​

- Use the correct membership operator to check if "apple" is present in the fruits object.
fruits = ["apple", "banana"]
if "apple" in fruits :
print("Yes, apple is a fruit!")

- x = {"name" : "John", "age" : 36 }
print(type(x))
>>> dict


- x = ("apple", "banana", "cherry")
print(type(x))
>>> tuple



-
Use the append method to add "orange" to the fruits list.
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")

- Change the value from "apple" to "kiwi", in the fruits list.
fruits = ["apple", "banana", "cherry"]
fruits [0] = " kiwi "

- Use the insert method to add "lemon" as the second item in the fruits list.
fruits = ["apple", "banana", "cherry"]
fruits.insert (1, "lemon")



- Use the correct syntax to print the first item in the fruits tuple.
fruits = ("apple", "banana", "cherry")
print(fruits[0])
 
×
Quay lại
Top