在Python中,变量类型是固定的,一旦声明就不能修改其类型(在Python里感觉不应该用声明,而应该用使用)

正确:

 var = 1
print(var)
var = 2
print(var)

依次输出变量var的值,1和2。

错误:

 var = 1
print(var)
var = "我是变量"
print(var)

编译错误,在第三行报错。

Python中的数据类型:

Boolean isClosed=True
Integer age=18
Float height=1.70
String message="Hello world"或message='Hello world'
List list=[1,2,3,4,5]
Tuple tuple=(1,2,3,4,5)
Dict dict={'Tom':18,'Lily':20}
Set set={1,2,3,4,5}

备注:Tuple是简化的List,一旦初始化就无法修改。Set是集合,元素无法重复。空集合创建:set()

Python中的字符串。

在Python中声明字符串可以用单引号或者双引号:

 var = 'hello'
var2 = "hello"
print(var==var2)

则输出True。

字符串的分割:

 var = 'I am Tom\n ,and you?'
words = var.split()
print(words)

则将会输出

['I', 'am', 'Tom', ',and', 'you?']

Python默认按空格和换行进行字符串的分割

字符串的连接:

 words = ['I','am','Tom']
str = ' '.join(words)
print(str)

则输出:

I am Tom

Python学习-5.Python的变量与数据类型及字符串的分割与连接的更多相关文章

  1. Python第三天 序列 5种数据类型 数值 字符串 列表 元组 字典 各种数据类型的的xx重写xx表达式

    Python第三天 序列  5种数据类型  数值  字符串  列表  元组  字典 各种数据类型的的xx重写xx表达式 目录 Pycharm使用技巧(转载) Python第一天  安装  shell ...

  2. Python学习day09 - Python进阶(3)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  3. Python学习day07 - Python进阶(1) 内置方法

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  4. Python学习day05 - Python基础(3) 格式化输出和基本运算符

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  5. python学习之第三课时--基本数据类型及区别,变量

    基本数据类型及区别 1. 数字类型(int) 数字型--变量值直接是数字,没有双引号""   整数 2. 浮点数(float) 肤浅理解小数点后有有效数字  1.55  0.22 ...

  6. Python学习(3)变量类型

    目录 变量赋值 多个变量赋值 标准数据类型 Python数字 Python字符串 Python列表 Python元组 Python元字典 Python数据类型转换 type数据类型查看 变量赋值 Py ...

  7. python学习小结7:变量类型

    变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中. 因此,变量可以指定不同的数据类型,这些变量可以存储整 ...

  8. Python基础(1)——变量和数据类型[xiaoshun]

    目录 一.变量 1.概述 Variables are used to store information to be referenced(引用)and manipulated(操作) in a co ...

  9. python学习笔记(5-1)-基本数据类型-字符串类型及操作

    五.字符串处理函数  len(x):字符串x的长度.如len("12345")结果为5  str(x):任意类型x所对应的字符串形式. >>> str(123) ...

随机推荐

  1. 关于filter web api mvc 权限验证 这里说的够详细了。。。

    参考:http://www.cnblogs.com/willick/p/3331520.html Filter(筛选器)是基于AOP(面向方面编程)的设计,它的作用是对MVC框架处理客户端请求注入额外 ...

  2. postman全方位讲解(有空看下)

    Postman 接口测试神器 Postman 是一个接口测试和 http 请求的神器,非常好用. 官方 github 地址: https://github.com/postmanlabs Postma ...

  3. thinkPHP使用函数时字符串中不能含有管道符”|“,否则报错;

    如 {$data.name|str_repeat="|",###}报错!!!

  4. ubuntu安装tushare

    sudo apt-get install python-pandas sudo pip install tushare

  5. C++ 并发编程 01 线程api

    1.使用多线程的好处: 提高性能,分离关注点  2. 多线程所在头文件 <thread> 3. 使用线程方式为std::thread(functioncall),如: #include & ...

  6. 「小程序JAVA实战」小程序搜索功能(55)

    转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxusousuogongneng54/ 通过用户搜索热销词,将热销词添加到 ...

  7. fireDAC oracle

    copy 4 files to D:\oracleapp\Administrator\product\11.2.0\client_1\BIN setup win 64 bit client .down ...

  8. JVM 调优参数设置

    先看Linux内存大小(假设为2G) cat /proc/meminfo |grep MemTotal 查看java初始配置 java -XX:+PrintFlagsInitial Tomcat配置 ...

  9. window10上安装python+CUDA+CuDNN+TensorFlow

    软件 版本 Window10 X64 python 3.6.4(64位) CUDA CUDA Toolkit 9.0 (Sept 2017) CuDNN cuDNN v7.0.5 (Dec 5, 20 ...

  10. UNITY Destroy()和DestroyImadiate()的区别

    using System.Collections; using System.Collections.Generic; using System.Timers; using UnityEngine; ...