Python的学习中细节的整理(3):raw_input

raw_input的功能,总的来说,就一句: 将输入的内容读入,并且可以将其赋给相关的变量。
    具体的说来,可将此功能用于一下几个方面:
   function 1. just simply put in a value, which will be assigned to certain variable(variables). And this function is to some extent similar as the <cin>functions in C++ programming language:  
```
var_type var_1;
cout <<"input the first variable:";
cin>>var_1;
```
accordingly,  in python programming, we have the similar useage as follows:
```
print"how old are you?",
age = raw_input()
```
Pay attention to the 'comma<,>’at the end of <print ... ...>sentence, which is used to temporarily suspend the <print>operation, until a value is given to variable <a>,and by putting in  the value of <a> with your keyboard, this value can be meanwhile shown on the terminal.
The running results is the following:
![](https://img-blog.csdn.net/20160827085713269)
![](https://img-blog.csdn.net/20160827085412771)
An <Enter>press-button operation was conducted after inputting the age, after which the variable 'a' was given a value of '465465'. And if you want to print variable 'a', this value will be on the terminal(in general , a screen,hahaha...).Example is given in the following:

```
print"How old are you?",  
#please keep in mind not leaving out the comma<,>
#if you want to input a value by means of reminding, 
#ie, a scentence shown on the screen tells you to input something ,and you input it.
age= raw_input();
print "How tall are you?",
height = raw_input();
print "you are %r old, and %r tall."%(age, height)
```
*Running output:*
![](https://img-blog.csdn.net/20160827091537012)
<Note: if you do not want input value by reminding scentences, you can also use raw_input( ) like the following:

```
year = raw_input();
print "year now is: %r" %year
```
*Running output:*
![](https://img-blog.csdn.net/20160827093700003)![](https://img-blog.csdn.net/20160827093713819)
>

**function 2.**   using raw_input( ) scentences to remind others somthing:

```
age = raw_input("How old are you? ")
height = raw_input("how tall are you? ")
print "you are %r old and %r tall" %(age, height)
```
*Running output:*
![](https://img-blog.csdn.net/20160827095921910)
![input the variable<age>](https://img-blog.csdn.net/20160827095951302)
![after input, press <Enter>button](https://img-blog.csdn.net/20160827100046142)
![input the variable<height>, and then press <Enter >button](https://img-blog.csdn.net/20160827100150252)

another form of reminding: using some peculiar characters as the reminding part
example:
prompt = '>>> ' print "What kind of computer do you have?" computer = raw_input(prompt) print "You said you have a %r " %computer 


Running output:
(use 'prompt' characters(>>>)as a reminding to inform others input value for certain varaibles)




 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值