“Tausch in Python” Code-Antworten

Tausch in 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

Python -Swap -Funktion

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

Swap Case Python

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

rfind () in Python

#Python rfind() method finds a substring in in the string and returns the highest index. It means it returns the index of most righmost matched subtring of the string. It returns -1 if substring not found.
Spotless Spider

Ähnliche Antworten wie “Tausch in Python”

Fragen ähnlich wie “Tausch in Python”

Weitere verwandte Antworten zu “Tausch in Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen