变量在python可以是字符也可以是数字。例如:
 
x = 2
price = 2.5
word = 'Hello'
 
变量名在等号左边,值在右边,一旦变量被指定,就可以在程序的其他地方使用它。
在上面的例子中,我们有三个变xprice and word,
变量名中不能有空格和特殊字符。
字符变量有三种定义方法:
 
 
word = 'Hello'
word = "Hello"
word = '''Hello'''
 
这取决于你的喜好,变凉定义之后是可以被替换和修改的。
 
x = 2
 
# increase x by one
x = x + 1
 
# replace x
x = 5
 
Python支持运算符+、-、/ *以及括号。变量可以使用print语句显示在屏幕上。
 
x = 5
print(x)
 
y = 3 * x
print(y)
 
# more detailed output
print("x = " + str(x))
print("y = " + str(y))
 
上面的第一个程序的输出是变量的原始值。这个str()函数将数值变量转换为文本。

4.variables的更多相关文章

  1. Tcl internal variables

    Tcl internal variables eryar@163.com 在Tcl中内置了一些变量,并赋予了一定的功能.内置变量列表如下: 变量名称 功能描述 argc 指命令行参数的个数. argv ...

  2. [Project Name] was compiled with optimization - stepping may behave oddly; variables may not be available.

    控制台输出的时候显示一串这样的信息:[Project Name] was compiled with optimization - stepping may behave oddly; variabl ...

  3. Examples of MIB Variables - SNMP Tutorial

    30.5 Examples of MIB Variables Versions 1 and 2 of SNMP each collected variables together in a singl ...

  4. foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because 'System.Web.UI.WebControls.Table' does not contain a public definition for 'GetEnumerator'

    错误:foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.Table' because ' ...

  5. 已解决:Strict Standards: Only variables should be passed by reference in

    今天安装ecshop的时候最上面出现了一个错误提示:Strict Standards: Only variables should be passed by reference in F:\www.x ...

  6. T-SQL Recipes之 Table Variables and Temporary Tables

    Problem 许多时候, 我们想要Table Variables在动态SQL中执行,但现实是很骨感的.比如这个示例: DECLARE @sql_command NVARCHAR(MAX); DECL ...

  7. PHP 笔记一(systax/variables/echo/print/Data Type)

    PHP stands for "Hypertext Preprocessor" ,it is a server scripting language. What Can PHP D ...

  8. show status和show variables区别解析

    1.show status    查看系统运行的实时状态,便于dba查看mysql当前运行的状态,做出相应优化,动态的,不可认为修改,只能系统自动update. MariaDB [(none)]> ...

  9. MySQL JDBC 出现多个 SHOW VARIABLES 语句。

    一次偶然的机会,show processlist 的时候,发现有个 Client 一直在执行  "mysql-connector-java-5.1.21 ( Revision: ${bzr. ...

  10. Java environment variables and their functionality

    Explanations of Functionalities: 1. PATH env variable It is used to search the command directory whe ...

随机推荐

  1. css怎样让背景充满整个屏幕

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. F12调试模式下使用console自动提交

    F12调试模式下使用console自动提交(F12 的console->输入代码->按enter即可运行) 1.使用定时器setInterval进行自动提交 //方法中可使用jquery调 ...

  3. 史上最强学生管理系统之IO版

    既上一博发布的ArrayList版本之后,新一版的IO版又来了,其实只是在上一个版本里面添加了IO流的内容,将存入更改的信息更新到了文件中而已,这个版本网上仍然很多,本人只是在某些方面稍加修改,因为自 ...

  4. this的理解

    this的理解 看了阮一峰的this讲解,下面是我的理解: 总结来说 this指向 调用this所在方法 的对象: 普通函数 例子1 function test(){ this.x = 1; cons ...

  5. Django实战,小网站实现增删改查

    直接上代码 视图: from django.shortcuts import render,render_to_response, redirect from submit import models ...

  6. 历史命令~/.bash_history,查看所有别名alias,命令执行顺序,命令行常用快捷键,输入输出重定向,wc统计字节单词行数

    历史命令大小:/etc/profile中字段HISTSIZE=1000 历史命令保存文件:~/.bash_history history -c 清空历史命令 history -w 把历史命令写入~/. ...

  7. IOS学习8——常用框架学习汇总

    我们在学习和code过程中经常会用到一些框架,本文将会持续更新最新学习和用到的框架 布局框架: Masonry介绍与使用实践:快速上手Autolayout iOS MJRefresh下拉.上拉刷新自定 ...

  8. iOS APP之间到跳转,以及热门应用,手机自带到应用跳转

    应用之间的跳转 在第一个APP中,做如下操作:1.在info.plist文件中的"信息属性列表"下添加一项:"URL类型"; 2.点开"URL类型&q ...

  9. iOS 数据储存--SQLite 操作数据库-FMDB,sqlite数据类型,保存图片,demo

    1.SQLite 语句中 数据类型的储存 /* 不区分大小写 char(长度).字符串 NULL. 空值 INTEGER. 整型 REAL.浮点型 TEXT.文本类型 BLOB. 二进制类型,用来存储 ...

  10. go实例之排序

    1.默认排序 使用sort包进行排序.排序是就地排序,因此它会更改给定的切片,并且不返回新的切片. package main import "fmt" import "s ...