Par*_*aH2 5 alphabet python-3.x
我需要知道文本中第n个字符的字母位置,我读了这个问题的答案,但它不适用于我的Python 3.4
我的节目
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 22 12:24:15 2016
@author: Asus
"""
import string
message='bonjour'
string.lowercase.index('message[2]')
Run Code Online (Sandbox Code Playgroud)
它不适用于ascii_lowercase而不是小写.
错误消息
runfile('C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py',wdir ='C:/ Users/Asus/Desktop/Perso /WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts')Traceback(最近一次调用最后一次):
文件"",第1行,在runfile中('C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py',wdir ='C: /Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts')
文件"C:\ Users\Asus\Desktop\Perso\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第685行,in runfile execfile(文件名,命名空间)
文件"C:\ Users\Asus\Desktop\Perso\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第85行, execfile exec(compile(open(filename,'rb').read(),filename,'exec'),namespace
在string.lowercase.index('message 2 ')中输入文件"C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py",第11行)
AttributeError:'module'对象没有属性'lowercase'
import string
message='bonjour'
print(string.ascii_lowercase.index(message[2]))
Run Code Online (Sandbox Code Playgroud)
输出/输出
13
Run Code Online (Sandbox Code Playgroud)
这对您有用,删除'更改索引。
当你给出''时,它将被视为一个字符串。
| 归档时间: |
|
| 查看次数: |
3262 次 |
| 最近记录: |