在Python 2.7中进行用户输入 [英] Take user input in Python 2.7
本文介绍了在Python 2.7中进行用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是使用 class 和对象的简单python 2.7代码。
Below is a simple python 2.7 code using class and objects.
class Student:
def __init__(self,name,pref):
self.name = name
self.preference = pref
student1=Student("Tom","cce")
print(student1.name)
print(student1.preference)
如何实现此代码,以便名称和首选项值(字符串)是使用用户输入( raw_input())
How can this code be implemented so that the name and preference values(string) are taken using user-input(raw_input())
推荐答案
这也是有效的代码。
class Student:
def __init__(self,name,pref):
self.name = name
self.preference = pref
student1=Student(raw_input("enter name:"),raw_input("enter branch:"))
print(student1.name)
print(student1.preference)
这篇关于在Python 2.7中进行用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文