“Pertukaran Kasus Python” Kode Jawaban

Mengubah huruf kapital menjadi huruf kecil dan sebaliknya di Python

s=input()
new_str=""
for i in range (len(s)):
    if s[i].isupper():
        new_str+=s[i].lower()
    elif s[i].islower():
        new_str+=s[i].upper()
    else:
        new_str+=s[i]
print(new_str)
        
        
Homeless Hawk

Swapcase

str_swapcase = "what was that about?".swapcase()
print(str_swapcase)
rajib2k5

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

menukar huruf besar dan string huruf kecil Python

# swapcase() method 

string = "thE big BROWN FoX JuMPeD oVEr thE LAZY Dog"
print(string.swapcase()) 

>>> THe BIG brown fOx jUmpEd OveR THe lazy dOG
Aggressive Addax

Pertukaran Kasus Python

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

Jawaban yang mirip dengan “Pertukaran Kasus Python”

Pertanyaan yang mirip dengan “Pertukaran Kasus Python”

Lebih banyak jawaban terkait untuk “Pertukaran Kasus Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya