佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1570|回复: 6

学习 phyton --> 求助 :: ("和")的问题 <4楼>

[复制链接]
kr_kryptom 该用户已被删除
发表于 4-2-2006 12:14 PM | 显示全部楼层 |阅读模式
Even if it is the same variable on both sides the computer still reads it as: First find out the data to store and than find out where the data goes.

One more program before I end this chapter:

num = input("Type in a Number: ")
str = raw_input("Type in a String: ")
print "num =", num
print "num is a ",type(num)
print "num * 2 =",num*2
print "str =", str
print "str is a ",type(str)
print "str * 2 =",str*2

The output I got was:

Type in a Number: 12.34
Type in a String: Hello
num = 12.34
num is a  <type 'float'>
num * 2 = 24.68
str = Hello
str is a  <type 'string'>
str * 2 = HelloHello


Notice that num was gotten with input while str was gotten with raw_input. raw_input returns a string while input returns a number. When you want the user to type in a number use input but if you want the user to type in a string use raw_input.

The second half of the program uses type which tells what a variable is. Numbers are of type int or float (which are short for 'integer' and 'floating point' respectively). Strings are of type string. Integers and floats can be worked on by mathematical functions, strings cannot. Notice how when python multiples a number by a integer the expected thing happens. However when a string is multiplied by a integer the string has that many copies of it added i.e. str * 2 = HelloHello.

The operations with strings do slightly different things than operations with numbers. Here are some interative mode examples to show that some more.

能帮我弄红色字的给他容易明白一点吗?
string = str? , raw_input  <-- 解释一下吗?
string又是什么?

[ 本帖最后由 kr_kryptom 于 8-2-2006 12:18 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 4-2-2006 04:44 PM | 显示全部楼层
虽然我没学过python , 应该还可以助你一臂之力。

你应该是一个完全初学者, 你需要了解编程的基本, variable 的概念才行。

大略来说, variable 是一个储藏资料(值, value)的暂时地点(在记忆体内)。

variable 的种类, 基本上有 String 和 numeric 两种。

在这个程序中, raw_input 是用来得到一个String 值(value)而 input 是用来得到一个numeric 的值(value)。


先把variable 概念搞清楚, 才去了解源代码。

学编程重要的不是理论, 是hands-on。 强烈建议你到www.python.org 下载python  Windows 版 , 安装了, 键入程序源代码, 然后自己执行测试。

[ 本帖最后由 jangancari 于 4-2-2006 04:46 PM 编辑 ]
回复

使用道具 举报

kr_kryptom 该用户已被删除
 楼主| 发表于 4-2-2006 05:34 PM | 显示全部楼层
phyton for non programer

我都是用上面这个教程来学

>你应该是一个完全初学者,
哈,被你说中

> 强烈建议你到www.python.org 下载python  Windows 版
已经安装了,但执行测试了还不懂<悟性低?>没办法

>学编程重要的不是理论, 是hands-on
我爱编程因为着重hands-on

谢了,终于懂了

以后会更多...
回复

使用道具 举报

kr_kryptom 该用户已被删除
 楼主| 发表于 8-2-2006 12:14 AM | 显示全部楼层
num = input("Type in a Number: ")
str = raw_input("Type in a String: ")
rate = input("Rate:")
distance = input("Distance:")

只有 ("和") 之间 <青色字> 才会显示出来
("和")的功能和 PRINT 一样吗?

rate = input, print "Rate:"
出现ERROR,是哪里出问题


只是想确定,不想误会了本来的功能
回复

使用道具 举报

发表于 8-2-2006 12:46 PM | 显示全部楼层
趁还没有上飞机前帮你一把。

之前我有提到关于variable 的种类, string 。

在编程世界, 要让电脑知道一段文字, 都是用 " " 来表示。

例子:

  print "One sentence"


如果没有使用 " "

  print One sentence

这样的话, 电脑会混乱, 分辨不出One sentence 到底是command 还是不是。


= = =

input/raw_input 是一个函数(function) , 可以打印出一段字, 然后等待使用者键入一些资料
而 print 纯粹是一个可以打印出一段字的函数。


= = =
rate = input, print "Rate:"

以上的一段会有问题,正确应该是 rate = input("Rate :")

电脑语言和普通语言一样, 有一定的语法syntax (grammer) 。

这行有问题因为你把 print 用一个 逗号在 input 后面, 这是语法不允许的。

你可以尝试以下的几个小程序, 来研究

= 第一 =
rate = input("Key in rate :")

print "Show something"


= 第二 =

rate = input("Key in rate :")

print rate


= 第三 =

rate = input("Key in rate :")

print “The rate you key in is " rate

= =


以上小程序没有经过测试, 可能有错误。 而且, 我也不会python。
回复

使用道具 举报

发表于 28-11-2017 06:31 PM | 显示全部楼层
有谁可以指点我吗?我是个完全新手甚至还不懂pyton可以干什么,只是看到他的用途广泛然后想提升自己,我该从哪看起。

各位大师请指点。
回复

使用道具 举报

Follow Us
发表于 12-1-2018 11:28 PM | 显示全部楼层
咖啦啡 发表于 28-11-2017 06:31 PM
有谁可以指点我吗?我是个完全新手甚至还不懂pyton可以干什么,只是看到他的用途广泛然后想提升自己,我该从哪看起。

各位大师请指点。

只要有安装 python,
其它平台都可运行 python 写的程序.
当然它可以用于编写网站如 Youtube 就是用 Python 写的,
也可以配合数据库来用.

建议如果要学 Python, 建议用 Linux,
因通常已自动安装上了 Pyton 2 和 3 的版本
(如果要用其它 Python library, 还是要另外安装)

http://www.runoob.com/python/python-tutorial.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 26-4-2024 04:40 AM , Processed in 0.094302 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表