zoukankan      html  css  js  c++  java
  • python学习笔记一

    1. python是一种解释语言,不需要编译,但是它的运行效率并不低,因为它产生的是一种近似机器语言的中间形式,是通过字节编译的。
    2. 查看python解释器的安装路径
       import sys     
       print (sys.path) 

    3 输出方式和C语言相似

    num = raw_input('please input a number:')
    num = int(num)*2
    print ('doubling your number:%d' %num)

    这里要注意的是raw_input()方式输入的是字符串的形式,如果要进行数字运算还要进行数值类型的转换 ,输出结果为

    please input a number:123
    doubling your number:246

    4.python的对大小写敏感
    5.python是动态性语言,不需要事先定义变量,变量的类型和值在赋值的时候就被初始化。
    6.python不支持自增和自减的操作,因为+-都是单目运算符,python 会这样解释:-(-n)=n
    7.字符串的索引值:第一个下标为0,最后一个下标为-1,[:]指定下标
    8.列表和元组的区别:

    alist=[1,2,3,4,5,6]
    print alist[0]
    print alist[1:5]
    alist[0]=100
    print alist
    print alist[:4]

    运行结果:

    1
    [2, 3, 4, 5]
    [100, 2, 3, 4, 5, 6]
    [100, 2, 3, 4]
    

    元组

    atuple=(1,2,3,'hello',6,4,4)
    print atuple[0]
    print atuple[1:4]
    atuple[0]=100
    print atuple

    运行结果

    1
    (2, 3, 'hello')
    Traceback (most recent call last):
      File "H:/������/study/test_1.py", line 11, in <module>
        atuple[0]=100
    TypeError: *'tuple' object does not support item assignment*
    
    Process finished with exit code 1 
    
    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    java——io、字节流缓冲区拷贝文件、字节缓冲流
    java——斗地主小游戏之洗牌发牌
    java——HashMap、Hashtable
    java——模拟新浪微博用户注册
    [bzoj 1492][NOI2007]货币兑换Cash
    [bzoj 1010][HNOI 2008]玩具装箱
    [bzoj 2875][noi2012]随机数生成器
    [bzoj 4872][六省联考2017]分手是祝愿
    [bzoj 3566][SHOI 2014]概率充电器
    [bzoj 3534][Sdoi2014] 重建
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10428332.html
Copyright © 2011-2022 走看看