zoukankan      html  css  js  c++  java
  • python学习2——变量和命名。

    命名变量

    1、= 是赋值的符号,== 才表示等于。

    2、命名时用 _ 代替空格。

    3、命名是用引号表示字符串。

    4、介绍几个格式化字符,类似的还有很多

          %a     浮点数、十六进制数字

          %c     字符

          %d     有符号十进制整数

          %f      浮点数

          %s     字符串

    5、交互式命名:

    num_1, num_2 = 5, 6

    如:

    >>> my_height = "160"
    
    >>>print("She is %d cm tall." %my_height)
    Traceback (most recent call last):
    File "<pyshell#9>", line 1, in <module>
    print("She is %d cm tall." %my_height)
    TypeError: %d format: a number is required, not str

    由于变量命名时用了双引号,所以不能用%d,需要去掉双引号或者使用%s 引用。

    >>> my_height = 160
    >>> print("She is %d cm tall." %my_height)
    She is 160 cm tall.

      >>> my_height = "160"
      >>> print("She is %s cm tall." %my_height)
      She is 160 cm tall.

  • 相关阅读:
    Ruby窗口程序
    RubyWin32Api Win32OLE
    Ruby网络服务
    Ruby 文件处理
    Ruby基础数据类型
    Ruby基础类型,动态特性,代码块
    Ruby类,模块1
    Ruby准备工作
    js变量作用域
    ExecuteStoreQuery
  • 原文地址:https://www.cnblogs.com/shannon-V/p/9493889.html
Copyright © 2011-2022 走看看