“Fungsi Swap Python” Kode Jawaban

Tukar di Python

# Python program to swap two variables

x = 5
y = 10

# To take inputs from the user
#x = input('Enter value of x: ')
#y = input('Enter value of y: ')

# create a temporary variable and swap the values
temp = x
x = y
y = temp

print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
Amused Armadillo

Fungsi Swap Python

def swap0(s1, s2):
    assert type(s1) == list and type(s2) == list
    tmp = s1[:]
    s1[:] = s2
    s2[:] = tmp
    
# However, the easier and better way to do a swap in Python is simply:
s1, s2 = s2, s1
Gorgeous Goshawk

Pertukaran Kasus Python

t = "Mr.Brown"
nt = t.swapcase()
print(nt)
Silver Takana

Jawaban yang mirip dengan “Fungsi Swap Python”

Pertanyaan yang mirip dengan “Fungsi Swap Python”

Lebih banyak jawaban terkait untuk “Fungsi Swap Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya