Python基础02 基本数据类型

	<div class="clear"></div>
	<div class="postBody">
		<div id="cnblogs_post_body" class="blogpost-body"><p></p>

 

简单的数据类型以及赋值

 

变量不需要声明

Python的变量不需要声明,你可以直接输入:

>>>a = 10

那么你的内存里就有了一个变量a, 它的值是10,它的类型是integer (整数)。 在此之前你不需要做什么特别的声明,而数据类型是Python自动决定的。

>>>print(a)

>>>print(type(a))

那么会有如下输出:

10
<class 'int'>

 

这里,我们学到一个内置函数type(), 用以查询变量的类型。

 

回收变量名

如果你想让a存储不同的数据,你不需要删除原有变量就可以直接赋值。

>>>a = 1.3

>>>print(a,type(a))

会有如下输出

 

1.3 <class 'float'>

 

我们看到print的另一个用法,也就是print后跟多个输出,以逗号分隔。

 

基本数据类型

a=10         # int 整数

a=1.3        # float 浮点数

a=True       # 真值 (True/False)

a='Hello!'   # 字符串。字符串也可以用双引号。

以上是最常用的数据类型。此外还有分数,字符,复数等其他类型,有兴趣的可以学习一下。

 

总结

变量不需要声明,不需要删除,可以直接回收适用。

type(): 查询数据类型

整数,浮点数,真值,字符串

如果你喜欢这篇文章,欢迎推荐

技术推动进步,分享促进社区。

标签: Python
18
0
« 上一篇:Python基础01 Hello World!
» 下一篇:Python基础03 序列
	</div>
	<div class="postDesc">posted @ <span id="post-date">2012-05-28 20:05</span> <a href="http://www.cnblogs.com/vamei/">Vamei</a> 阅读(<span id="post_view_count">115991</span>) 评论(<span id="post_comment_count">27</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=2522385" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(2522385);return false;">收藏</a></div>
</div>
<script type="text/javascript">var allowComments=true,cb_blogId=118754,cb_entryId=2522385,cb_blogApp=currentBlogApp,cb_blogUserGuid='3faf47ff-9ea8-e111-aa3f-842b2b196315',cb_entryCreatedDate='2012/5/28 20:05:00';loadViewCount(cb_entryId);var cb_postType=1;</script>
	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2559872,'Qz+7E/lronkAhzbrTagO+gERApH/y8G3fpk+rsPRcyzIzCHLSaTlYw==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2559872,'Qz+7E/lronkAhzbrTagO+gERApH/y8G3fpk+rsPRcyzIzCHLSaTlYw==')">引用</a></span>
			</div>
			<a href="#2559872" class="layer">#1楼</a><a name="2559872" id="comment_anchor_2559872"></a>  <span class="comment_date">2012-11-22 19:58</span> <a id="a_comment_author_2559872" href="http://www.cnblogs.com/RainingDays/" target="_blank">Raining Days</a> <a href="http://msg.cnblogs.com/send/Raining%20Days" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2559872" class="blog_comment_body">我是初学者,毕竟要毕业了多学一点十一点,之前一直是c/c++的编程,也有参加过相应的比赛。这阵子不是特别忙,就想学点什么。之后再在博主这里学学linux。<br>我是刚来看的,这么说的话,在python里面可以随心所欲的定义数据,而且它会自动分配一个合适的数据类型给你,一个变量,可以是多种类型了吧。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(2559872,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(2559872,'Bury',this)">反对(1)</a></div><span id="comment_2559872_avatar" style="display:none;">http://pic.cnblogs.com/face/397161/20130507205142.png</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2559875,'Qz+7E/lronkAhzbrTagO+gERApH/y8G3fpk+rsPRcyzIzCHLSaTlYw==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2559875,'Qz+7E/lronkAhzbrTagO+gERApH/y8G3fpk+rsPRcyzIzCHLSaTlYw==')">引用</a></span>
			</div>
			<a href="#2559875" class="layer">#2楼</a><a name="2559875" id="comment_anchor_2559875"></a>  <span class="comment_date">2012-11-22 20:00</span> <a id="a_comment_author_2559875" href="http://www.cnblogs.com/RainingDays/" target="_blank">Raining Days</a> <a href="http://msg.cnblogs.com/send/Raining%20Days" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2559875" class="blog_comment_body">我刚才有试过a=-1/5,可是输出来的a=-1,而且我试过a=-2i+3,想要输出发现有错误,求博主解释一下。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(2559875,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(2559875,'Bury',this)">反对(0)</a></div><span id="comment_2559875_avatar" style="display:none;">http://pic.cnblogs.com/face/397161/20130507205142.png</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2559912,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2559912,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">引用</a></span>
			</div>
			<a href="#2559912" class="layer">#3楼</a><a name="2559912" id="comment_anchor_2559912"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2012-11-22 20:26</span> <a id="a_comment_author_2559912" href="http://www.cnblogs.com/vamei/" target="_blank">Vamei</a> <a href="http://msg.cnblogs.com/send/Vamei" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2559912" class="blog_comment_body"><a href="#2559875" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2559875);">@</a>

Raining Days
第一个问题:
因为两个参与运算的数字都是整数,所以它默认结果为整数。
你可以尝试 a = -1.0/5 或者 a = -1/5.0。由于参与运算中有一个是浮点数,所以整数会转换成更高精度的浮点数,再进行运算。
你也可以尝试 a = -float(1)/5,原理一样。

第二个问题,虚部是j,不是i
>>> a = 3 - 2j
>>> b = 2 + 1j
>>> a + b
(5-1j)



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2559915,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2559915,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">引用</a></span>
			</div>
			<a href="#2559915" class="layer">#4楼</a><a name="2559915" id="comment_anchor_2559915"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2012-11-22 20:27</span> <a id="a_comment_author_2559915" href="http://www.cnblogs.com/vamei/" target="_blank">Vamei</a> <a href="http://msg.cnblogs.com/send/Vamei" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2559915" class="blog_comment_body"><a href="#2559872" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2559872);">@</a>

Raining Days
关于动态类型,你可以查看后面的教程中的介绍。



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2571086,'L67wqPfN+C+6zICiEpxL/T/vepNxYuuOophJf33fnmrI2EQqPRXzmg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2571086,'L67wqPfN+C+6zICiEpxL/T/vepNxYuuOophJf33fnmrI2EQqPRXzmg==')">引用</a></span>
			</div>
			<a href="#2571086" class="layer">#5楼</a><a name="2571086" id="comment_anchor_2571086"></a>  <span class="comment_date">2012-12-06 00:28</span> <a id="a_comment_author_2571086" href="http://home.cnblogs.com/u/476590/" target="_blank">fz420</a> <a href="http://msg.cnblogs.com/send/fz420" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2571086" class="blog_comment_body">你好, 博主,<br><br>python 变量不需要声明<br><br>为什么下载这段代码中的   a  要先定义呢??<br><br><img src="//i.minus.com/iIM0SEvp3D4jg.jpg" alt="" border="0" "=""><br><br></div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(2571086,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(2571086,'Bury',this)">反对(0)</a></div>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2571238,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2571238,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">引用</a></span>
			</div>
			<a href="#2571238" class="layer">#6楼</a><a name="2571238" id="comment_anchor_2571238"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2012-12-06 10:04</span> <a id="a_comment_author_2571238" href="http://www.cnblogs.com/vamei/" target="_blank">Vamei</a> <a href="http://msg.cnblogs.com/send/Vamei" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2571238" class="blog_comment_body"><a href="#2571086" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2571086);">@</a>

fz420
是不需要声明类型。可你用在if判断里面,这个a总要是个什么东西吧,不然如何拿一个“虚无”的东西去做判断呢?



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2571454,'L67wqPfN+C+6zICiEpxL/T/vepNxYuuOophJf33fnmrI2EQqPRXzmg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2571454,'L67wqPfN+C+6zICiEpxL/T/vepNxYuuOophJf33fnmrI2EQqPRXzmg==')">引用</a></span>
			</div>
			<a href="#2571454" class="layer">#7楼</a><a name="2571454" id="comment_anchor_2571454"></a>  <span class="comment_date">2012-12-06 13:18</span> <a id="a_comment_author_2571454" href="http://home.cnblogs.com/u/476590/" target="_blank">fz420</a> <a href="http://msg.cnblogs.com/send/fz420" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2571454" class="blog_comment_body"><a href="#2571238" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2571238);">@</a>

Vamei

引用@fz420
是不需要声明类型。可你用在if判断里面,这个a总要是个什么东西吧,不然如何拿一个“虚无”的东西去做判断呢?


我觉得 if 与 for 的情况是相同的, 但是 for 可以执行不报错

1
2
3
4
5
6
7
#!/bin/python
 
 
#为什么这里a不用声明
 
for a in range(10):
       print a


	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2571472,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2571472,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">引用</a></span>
			</div>
			<a href="#2571472" class="layer">#8楼</a><a name="2571472" id="comment_anchor_2571472"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2012-12-06 13:34</span> <a id="a_comment_author_2571472" href="http://www.cnblogs.com/vamei/" target="_blank">Vamei</a> <a href="http://msg.cnblogs.com/send/Vamei" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2571472" class="blog_comment_body"><a href="#2571454" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2571454);">@</a>

fz420
当然不一样了。
for是把iterator生成的值赋予给a,然后再使用a。
if没有赋值这一步



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2718281,'9D+R++vwy7oeomuFcRWxA2J3cDdsPeCWsjzDQHdNTSMfyynRGci1Dw==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2718281,'9D+R++vwy7oeomuFcRWxA2J3cDdsPeCWsjzDQHdNTSMfyynRGci1Dw==')">引用</a></span>
			</div>
			<a href="#2718281" class="layer">#9楼</a><a name="2718281" id="comment_anchor_2718281"></a>  <span class="comment_date">2013-07-02 16:23</span> <a id="a_comment_author_2718281" href="http://home.cnblogs.com/u/544208/" target="_blank">boke_hh</a> <a href="http://msg.cnblogs.com/send/boke_hh" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2718281" class="blog_comment_body"><a href="#2559912" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2559912);">@</a>

Vamei
@Raining Days的第一个问题应该是3.0版本以下中出现的,3.0以上的版本中得到的值为-0.2。不需要考虑运算符前后元素的类型



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2718479,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2718479,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">引用</a></span>
			</div>
			<a href="#2718479" class="layer">#10楼</a><a name="2718479" id="comment_anchor_2718479"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2013-07-02 19:48</span> <a id="a_comment_author_2718479" href="http://www.cnblogs.com/vamei/" target="_blank">Vamei</a> <a href="http://msg.cnblogs.com/send/Vamei" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2718479" class="blog_comment_body"><a href="#2718281" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2718281);">@</a>

boke_hh
我之前还没有考虑过版本的问题,不错!



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2719477,'9D+R++vwy7oeomuFcRWxA2J3cDdsPeCWsjzDQHdNTSMfyynRGci1Dw==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2719477,'9D+R++vwy7oeomuFcRWxA2J3cDdsPeCWsjzDQHdNTSMfyynRGci1Dw==')">引用</a></span>
			</div>
			<a href="#2719477" class="layer">#11楼</a><a name="2719477" id="comment_anchor_2719477"></a>  <span class="comment_date">2013-07-03 18:35</span> <a id="a_comment_author_2719477" href="http://home.cnblogs.com/u/544208/" target="_blank">boke_hh</a> <a href="http://msg.cnblogs.com/send/boke_hh" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2719477" class="blog_comment_body"><a href="#2718479" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2718479);">@</a>

Vamei
博主,那个import怎么用啊,还有一些内置函数,查了下资料,还是不太明白



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2719811,'EO6lMMV76taORdC2CLcAAg5vzYictaujxVBkfGwNXRzvMuzFXp5tBg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2719811,'EO6lMMV76taORdC2CLcAAg5vzYictaujxVBkfGwNXRzvMuzFXp5tBg==')">引用</a></span>
			</div>
			<a href="#2719811" class="layer">#12楼</a><a name="2719811" id="comment_anchor_2719811"></a>  <span class="comment_date">2013-07-04 10:29</span> <a id="a_comment_author_2719811" href="http://home.cnblogs.com/u/539978/" target="_blank">jinghuali</a> <a href="http://msg.cnblogs.com/send/jinghuali" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2719811" class="blog_comment_body"><a href="#2719477" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2719477);">@</a>

boke_hh
import就是导入你需要的模块



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2895803,'0BOTkeGUidvWYDAIEcz0z+SmNhzzecoXfk11w4eHnEJEaFxs7tqkXA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2895803,'0BOTkeGUidvWYDAIEcz0z+SmNhzzecoXfk11w4eHnEJEaFxs7tqkXA==')">引用</a></span>
			</div>
			<a href="#2895803" class="layer">#13楼</a><a name="2895803" id="comment_anchor_2895803"></a>  <span class="comment_date">2014-03-14 21:40</span> <a id="a_comment_author_2895803" href="http://home.cnblogs.com/u/558035/" target="_blank">山之巅</a> <a href="http://msg.cnblogs.com/send/%E5%B1%B1%E4%B9%8B%E5%B7%85" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2895803" class="blog_comment_body">我有两个问题,一个是上一篇的问题,一起问了吧<br>1.我知道Linux的目录结构有树的概念,可以一直相对路径/找到文件,但是我用的windows,例如如果我安装在C盘,但是我在F盘建立了一个存放脚本的文件目录python script,建立了一个hello.py,我怎样通过命令执行这个脚本文件hello.py<br>2.9楼的说过得到的值是-0.2,这说明python默认把-1/2的-1当做float类型了,但是如果我现在想获得c语言中的-1/2的值,应该是0,我改成(int)-1/2或者-(int)1/2为什么都会报错,另外怎么实现像c语言一样</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(2895803,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(2895803,'Bury',this)">反对(0)</a></div>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2895837,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2895837,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">引用</a></span>
			</div>
			<a href="#2895837" class="layer">#14楼</a><a name="2895837" id="comment_anchor_2895837"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2014-03-14 22:52</span> <a id="a_comment_author_2895837" href="http://www.cnblogs.com/vamei/" target="_blank">Vamei</a> <a href="http://msg.cnblogs.com/send/Vamei" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2895837" class="blog_comment_body"><a href="#2895803" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2895803);">@</a>

山之巅
第一个问题,可以加上绝对路径执行。
第二个问题,你试试int(1)/int(2)?



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2897365,'0BOTkeGUidvWYDAIEcz0z+SmNhzzecoXfk11w4eHnEJEaFxs7tqkXA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2897365,'0BOTkeGUidvWYDAIEcz0z+SmNhzzecoXfk11w4eHnEJEaFxs7tqkXA==')">引用</a></span>
			</div>
			<a href="#2897365" class="layer">#15楼</a><a name="2897365" id="comment_anchor_2897365"></a>  <span class="comment_date">2014-03-17 20:25</span> <a id="a_comment_author_2897365" href="http://home.cnblogs.com/u/558035/" target="_blank">山之巅</a> <a href="http://msg.cnblogs.com/send/%E5%B1%B1%E4%B9%8B%E5%B7%85" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2897365" class="blog_comment_body">1.我上网查了,可以通过cmd中f:\python script&gt;C:\Python33\python.exe hello.py这样才能执行,但是这样必须切换到脚本所在的目录,如果我想直接在python shell中执行呢?像这样&gt;&gt;&gt; f:\python script\hello.py,就报错了SyntaxError: invalid syntax(:会变成红色),怎样才能在shell中直接执行?<br>2.print(1/2);和print(int(1)/int(2));的答案都是0.5,看来是不行了?</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(2897365,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(2897365,'Bury',this)">反对(0)</a></div>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2897366,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2897366,'Vbw54O+7HsLA+9mlMI3W3vxkhVcKzpgYD8CuAa02Zzlv3wzmzxfEnA==')">引用</a></span>
			</div>
			<a href="#2897366" class="layer">#16楼</a><a name="2897366" id="comment_anchor_2897366"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2014-03-17 20:29</span> <a id="a_comment_author_2897366" href="http://www.cnblogs.com/vamei/" target="_blank">Vamei</a> <a href="http://msg.cnblogs.com/send/Vamei" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2897366" class="blog_comment_body"><a href="#2897365" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2897365);">@</a>

山之巅
1. 还真不知道能不能在Python内部运行Python脚本。应该有一些特殊方法可以做到,比如利用os包里的功能,运行外部命令?
2. 似乎彻底改掉了。我还在用2.7,所以无法复制你说的效果。



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2905438,'n+vWwiYC7b5tt+sfsoRGayjJtPMqf0Raydgp7xn9lriixQGtVtSPOQ==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2905438,'n+vWwiYC7b5tt+sfsoRGayjJtPMqf0Raydgp7xn9lriixQGtVtSPOQ==')">引用</a></span>
			</div>
			<a href="#2905438" class="layer">#17楼</a><a name="2905438" id="comment_anchor_2905438"></a>  <span class="comment_date">2014-03-27 14:25</span> <a id="a_comment_author_2905438" href="http://www.cnblogs.com/zeliliu/" target="_blank">Triangle23</a> <a href="http://msg.cnblogs.com/send/Triangle23" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_2905438" class="blog_comment_body">关于进制表示能否讲一下,如2**010=256,2**10=1024,谢谢</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(2905438,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(2905438,'Bury',this)">反对(0)</a></div><span id="comment_2905438_avatar" style="display:none;">http://pic.cnblogs.com/face/u300489.jpg?id=14181149</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3003689,'o9RxgUYB2DcgaYOfmxpkrU/NZ7Y1nQzEHF1cE3cGofVUrY9ndn3viw==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3003689,'o9RxgUYB2DcgaYOfmxpkrU/NZ7Y1nQzEHF1cE3cGofVUrY9ndn3viw==')">引用</a></span>
			</div>
			<a href="#3003689" class="layer">#18楼</a><a name="3003689" id="comment_anchor_3003689"></a>  <span class="comment_date">2014-08-08 17:43</span> <a id="a_comment_author_3003689" href="http://home.cnblogs.com/u/533669/" target="_blank">东篱雪</a> <a href="http://msg.cnblogs.com/send/%E4%B8%9C%E7%AF%B1%E9%9B%AA" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3003689" class="blog_comment_body"><a href="#2905438" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2905438);">@</a>

Triangle23
1、2010中的 010表示的是八进制,实际就是 010(八进制)= 18^1 + 08^0 = 8(十进制);
2、2
10中的10就是十进制当中的10;
3、所以:

2010 = 2^8 = 256;
2
10 = 2^10 = 1024;

4、关于进制的表示:

十进制:生活中最常用的;0,1,2...
十二进制:钟表的时针;
六十进制:钟表的分针和秒针;
二进制:101010101011(零和一表示),互联网最底层的数据表示;

八进制:010,076,... 一般前面无缘无故带个零的,你就要考虑是不是八进制 了,如果0后面的最大数没有超过8,那极有可能是八进制表示的数;

十六进制:0x091abcdef ,一般前面带有0x的,就是十六进制表示的数,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f 总共16个字符表示十六进制的数,一般都是计算十六进制转十进制;计算时,a表示10,b表示11,...,f表示15;IPV6就是用十六进制表示的。



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3031675,'mM1xSGYdSokWkZJAHhwW8rwxLrVG3cnKcjh+vsjoFtFQXkcOuMZL1g==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3031675,'mM1xSGYdSokWkZJAHhwW8rwxLrVG3cnKcjh+vsjoFtFQXkcOuMZL1g==')">引用</a></span>
			</div>
			<a href="#3031675" class="layer">#19楼</a><a name="3031675" id="comment_anchor_3031675"></a>  <span class="comment_date">2014-09-21 11:27</span> <a id="a_comment_author_3031675" href="http://home.cnblogs.com/u/646846/" target="_blank">vagabond1132</a> <a href="http://msg.cnblogs.com/send/vagabond1132" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3031675" class="blog_comment_body"><a href="#2559875" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2559875);">@</a>

Raining Days

应该是 -1/5.0
因为 默认为int 而不是float输出



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3034705,'kd2Ls88IyNFPMY5kD3lbyP9M05GXIjD3SI46OKFIna50z6fAjT7GWg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3034705,'kd2Ls88IyNFPMY5kD3lbyP9M05GXIjD3SI46OKFIna50z6fAjT7GWg==')">引用</a></span>
			</div>
			<a href="#3034705" class="layer">#20楼</a><a name="3034705" id="comment_anchor_3034705"></a>  <span class="comment_date">2014-09-25 20:18</span> <a id="a_comment_author_3034705" href="http://home.cnblogs.com/u/676156/" target="_blank">小驰子</a> <a href="http://msg.cnblogs.com/send/%E5%B0%8F%E9%A9%B0%E5%AD%90" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3034705" class="blog_comment_body">15楼兄弟说的第一个问题,把Python安装路径放到环境变量里应该就可以和在shell里一样直接输入.py文件</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3034705,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3034705,'Bury',this)">反对(0)</a></div>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3105550,'4O2TRxZlaWS/NrsT8ywT4KXl9e/S4ntnsxAtN0DmluPuogLlsp+OCg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3105550,'4O2TRxZlaWS/NrsT8ywT4KXl9e/S4ntnsxAtN0DmluPuogLlsp+OCg==')">引用</a></span>
			</div>
			<a href="#3105550" class="layer">#21楼</a><a name="3105550" id="comment_anchor_3105550"></a>  <span class="comment_date">2015-01-12 21:51</span> <a id="a_comment_author_3105550" href="http://www.cnblogs.com/7oranger/" target="_blank">oblivion</a> <a href="http://msg.cnblogs.com/send/oblivion" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3105550" class="blog_comment_body">b type int<br>为什么b=1/5 输出0<br>而 b=-1/5 输出-1</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3105550,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3105550,'Bury',this)">反对(0)</a></div>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3196862,'EN2yswQUaAsDDldUVP1n8KkKLtob5O4p+brSCLYgVOl8A/alK68Kog==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3196862,'EN2yswQUaAsDDldUVP1n8KkKLtob5O4p+brSCLYgVOl8A/alK68Kog==')">引用</a></span>
			</div>
			<a href="#3196862" class="layer">#22楼</a><a name="3196862" id="comment_anchor_3196862"></a>  <span class="comment_date">2015-05-30 17:01</span> <a id="a_comment_author_3196862" href="http://www.cnblogs.com/bkkl/" target="_blank">迷途ing</a> <a href="http://msg.cnblogs.com/send/%E8%BF%B7%E9%80%94ing" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3196862" class="blog_comment_body">b = 1/5 输出0 都是int型且是正数<br>b = -1/5 输出 -1  python带有负数除法是按距离来做除法运算也就-1 到 5的距离是6 6/5 = 1 然后在加上符号-<br>这一点可验证<br><div class="cnblogs_Highlighter sh-gutter"><div><div id="highlighter_828781" class="syntaxhighlighter  python"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="python functions">print</code> <code class="python keyword">-</code><code class="python value">1</code><code class="python keyword">/</code><code class="python value">5</code></div><div class="line number2 index1 alt1"><code class="python functions">print</code> <code class="python keyword">-</code><code class="python value">10</code><code class="python keyword">/</code><code class="python value">5</code></div><div class="line number3 index2 alt2"><code class="python functions">print</code> <code class="python value">10</code><code class="python keyword">/</code><code class="python keyword">-</code><code class="python value">5</code></div><div class="line number4 index3 alt1"><code class="python functions">print</code> <code class="python value">15</code><code class="python keyword">/</code><code class="python keyword">-</code><code class="python value">5</code></div><div class="line number5 index4 alt2"><code class="python functions">print</code> <code class="python keyword">-</code><code class="python value">16</code><code class="python keyword">/</code><code class="python value">5</code></div></div></td></tr></tbody></table></div></div></div><br>所以在取模运算时 商的结果会影响取模结果,c/c++ java 是求余</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3196862,'Digg',this)">支持(1)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3196862,'Bury',this)">反对(1)</a></div><span id="comment_3196862_avatar" style="display:none;">http://pic.cnblogs.com/face/763804/20150530161809.png</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3278690,'avO6FPcqzLDf1bRRx/Ga2Pwpdr6HXpp8cFcM9A2JNUXXqoXKkFWUtA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3278690,'avO6FPcqzLDf1bRRx/Ga2Pwpdr6HXpp8cFcM9A2JNUXXqoXKkFWUtA==')">引用</a></span>
			</div>
			<a href="#3278690" class="layer">#23楼</a><a name="3278690" id="comment_anchor_3278690"></a>  <span class="comment_date">2015-10-05 10:32</span> <a id="a_comment_author_3278690" href="http://home.cnblogs.com/u/521049/" target="_blank">苏生不惑</a> <a href="http://msg.cnblogs.com/send/%E8%8B%8F%E7%94%9F%E4%B8%8D%E6%83%91" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3278690" class="blog_comment_body"><a href="#3105550" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,3105550);">@</a>

oblivion
整数相除返回的是商



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3352636,'AMK3Isb4zajPkES1rdErVMdnyTdumUDR/FwvRQ2d8sIBiBHrDJVqlg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3352636,'AMK3Isb4zajPkES1rdErVMdnyTdumUDR/FwvRQ2d8sIBiBHrDJVqlg==')">引用</a></span>
			</div>
			<a href="#3352636" class="layer">#24楼</a><a name="3352636" id="comment_anchor_3352636"></a>  <span class="comment_date">2016-01-22 16:55</span> <a id="a_comment_author_3352636" href="http://www.cnblogs.com/yeayee/" target="_blank">yeayee</a> <a href="http://msg.cnblogs.com/send/yeayee" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3352636" class="blog_comment_body">第3课已巩固www.yeayee.com</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3352636,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3352636,'Bury',this)">反对(0)</a></div><span id="comment_3352636_avatar" style="display:none;">http://pic.cnblogs.com/face/816924/20170922082617.png</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3449909,'NSGxpG7/lopcloBEgMh2KItDEpzxzHhS4KrO1XV8R0+cOQI9Zfjrgg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3449909,'NSGxpG7/lopcloBEgMh2KItDEpzxzHhS4KrO1XV8R0+cOQI9Zfjrgg==')">引用</a></span>
			</div>
			<a href="#3449909" class="layer">#25楼</a><a name="3449909" id="comment_anchor_3449909"></a>  <span class="comment_date">2016-06-11 16:57</span> <a id="a_comment_author_3449909" href="http://www.cnblogs.com/twosnail/" target="_blank">两只蜗牛</a> <a href="http://msg.cnblogs.com/send/%E4%B8%A4%E5%8F%AA%E8%9C%97%E7%89%9B" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3449909" class="blog_comment_body"><a href="#3196862" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,3196862);">@</a>

迷途ing
博主,我感觉 -1 到 5的距离是5 5/5 = 1 然后在加上符号-
0 到 5的距离是4 4/5 = 0 ,不知道我说的对不对,刚看你博客学python



	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3525792,'VR/3qf47Iim00cWx4WnkjKXUI3KJKUSZOF7T957/TMApXim1QOc5qA==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3525792,'VR/3qf47Iim00cWx4WnkjKXUI3KJKUSZOF7T957/TMApXim1QOc5qA==')">引用</a></span>
			</div>
			<a href="#3525792" class="layer">#26楼</a><a name="3525792" id="comment_anchor_3525792"></a>  <span class="comment_date">2016-10-08 16:33</span> <a id="a_comment_author_3525792" href="http://www.cnblogs.com/scplee/" target="_blank">dao_lee</a> <a href="http://msg.cnblogs.com/send/dao_lee" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3525792" class="blog_comment_body">print(type(a))时,python2.x显示&lt;type 'int'&gt;,python3.x显示&lt;class 'int'&gt;。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3525792,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3525792,'Bury',this)">反对(0)</a></div><span id="comment_3525792_avatar" style="display:none;">http://pic.cnblogs.com/face/632374/20160511132915.png</span>
		</div>
	</div>

	<div class="feedbackItem">
		<div class="feedbackListSubtitle">
			<div class="feedbackManage">
				&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(3993866,'PoXBbdJ+YytzelqlPiKIXO2Ynqm8w5Vlxa4LNJ8iaWrW8ctfLyk5Vg==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(3993866,'PoXBbdJ+YytzelqlPiKIXO2Ynqm8w5Vlxa4LNJ8iaWrW8ctfLyk5Vg==')">引用</a></span>
			</div>
			<a href="#3993866" class="layer">#27楼</a><a name="3993866" id="comment_anchor_3993866"></a><span id="comment-maxId" style="display:none;">3993866</span><span id="comment-maxDate" style="display:none;">2018/6/8 10:28:04</span>  <span class="comment_date">2018-06-08 10:28</span> <a id="a_comment_author_3993866" href="http://www.cnblogs.com/suyuloying/" target="_blank">suyuloying</a> <a href="http://msg.cnblogs.com/send/suyuloying" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="feedbackCon">
			<div id="comment_body_3993866" class="blog_comment_body">&gt;&gt;&gt; a = 3 - 2j<br>&gt;&gt;&gt; b = 2 + 1j<br>&gt;&gt;&gt; a + b<br>(5-1j)<br><br>楼主  您好 请问下怎么查到复数是j而不是数学表达式中的i</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(3993866,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(3993866,'Bury',this)">反对(0)</a></div>
		</div>
	</div>
<div id="comments_pager_bottom"></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
</div><!--end: forFlow -->
</div>
posted @ 2018-07-26 23:45  韦大仙  阅读(576)  评论(0编辑  收藏  举报