Kama yin gurɗi tsontayi a Python
- Dafin Daga Daga Daga Dafin Daga Daga Kudi Kudi
- Dafin Daga Next Python Anfani
Kware a yin gurɗi tsontayi a Python.
Mai yin ciki a Python na ba na ba da hanyar zama hanyar yin gurɗi tsontayi.
Hausa ce (kuma na kisan?) na farko (kuma na duki?) na yin gurɗi ta ciciyari na gaba da gaba.-1
。
实例
Yin gurɗi tsontayi "Hello World":
txt = "Hello World"[::-1] print(txt)
例子解释
A ka da tsontayi, "Hello World", a sani ya yin gurɗi:
Tsontayi a yauwan zuwa ta yin gurɗi
txt = "Hello World" [::-1] print(txt)
Anfaiki ciciyari daga lokaci na tsaki na tsontayi, kuma ya tsaya zuwa gaba.
A fannanin na yauwan, ciciyari na slice [::-1]
等同于 [11:0:-1]
,这意味着从位置 11 开始(因为 "Hello "World" 有 11 个字符),结束于位置 0,移动步长 -1
,负一意味着向后退一步。
Dafin Daga Daga
txt = "Hello World" [::-1] print(txt)
现在我们有一个向后读取 "Hello World" 字符串 txt
。
打印字符串以演示结果
打印列表
txt = "Hello World"[::-1] print(txt)
创建函数
如果你想要一个可以发送字符串并向后返回它们的函数,那么可以创建一个函数并插入上例中的代码
实例
def my_function(x): return x[::-1] mytxt = my_function("I wonder how this text looks like backwards") print(mytxt)
例子解释
创建以字符串作为参数的函数。
创建函数
def my_function(x): return x[::-1] mytxt = my_function("I wonder how this text looks like backwards") print(mytxt)
从字符串末尾开始裁切字符串并向后移动。
Dafin Daga Daga
def my_function(x): return x [::-1] mytxt = my_function("I wonder how this text looks like backwards") print(mytxt)
Return Daga Yantattu.
Return Daga
def my_function(x): return x[::-1] mytxt = my_function("I wonder how this text looks like backwards") print(mytxt )
Dafin Daga daga kai tsaye kuma kuma daga fari:
Dafin Daga
def my_function(x): return x[::-1] mytxt = my_function("I wonder how this text looks like backwards") print(mytxt)
Dafin Daga:
Dafin Daga
def my_function(x): return x[::-1] mytxt = my_function("I wonder how this text looks like backwards") print(mytxt)
- Dafin Daga Daga Daga Dafin Daga Daga Kudi Kudi
- Dafin Daga Next Python Anfani