python学习第二天


python注释的使用

python中数据类型

pycharm的使用



1:在python语句里面添加注释,注释的作用增加代码的可读性,便与作者或者作者意外的人审阅代码。一个好的程序员,为代码加注释是必须要作的。但要确保注释要说的都是重要的事情,像看一眼就知道是干什么的,无用的代码是不需要加注释的。

注释方法1:单行注释,使用#。#号后面的不会在代码里面运行。

>>> a = 1 #这是注释,不会在代码中生效的
>>> print(a)
1

    #号还有就是声明的意识,一般在代码的开头会写上声明支持什么编码,如果开头不声明保存编码的格式是什么,那么它会默认使用ASKII码保存文件,这时如果你的代码中有中文就会出错了,即使你的中文是包含在注释里面的。所以加上中文注释很重要。

#coding=utf-8


注释方法2: 多行注释,使用''' '''或者是""" """

#Author: leslie
#2017/8/20 0020
user = input("please input username:")
"""
只是一个多行注释
可以注释多行内容
引号内的不在代码中生效
只起到提醒的作用
"""
print(user)





2:python中常用的数据类型:

可以使用type(数据)查看数据类型

    字符串
如何在Python中使用字符串
    a、使用单引号(')
用单引号括起来表示字符串,例如:
str='this is string';
print str;

>>> str = 'this is string'
>>> print(str)
this is string
>>> type(str)  #查看数据类型
<class 'str'>   ##数据类型为str,字符串类型


    b、使用双引号(")
双引号中的字符串与单引号中的字符串用法完全相同,例如:
str="this is string";
print str;

>>> str = "this is string"
>>> print(str)
this is string
>>> type(str)
<class 'str'>

    c、使用三引号(''')
利用三引号,表示多行的字符串,可以在三引号中自由的使用单引号和双引号,例如:
str='''this is string
this is pythod string
this is string'''
print str;

>>> str = '''this is str type'''
>>> print(str)
this is str type
>>> type(str)
<class 'str'>
>>> 

还可以这样写入多行到'''  '''
str = '''三个点也可以写作字符类型
而且可以写入多行
。。。
'''

    布尔类型
bool=False;
print bool;
bool=True;
print bool;

>>> a = True
>>> print(a)
True
>>> type(a)
<class 'bool'>

    整数
int=20;
print int;

>>> int=20
>>> print(int)
20
>>> type(int)
<class 'int'>

    浮点数
float=2.3;
print float;

>>> a = 2.3
>>> print(a)
2.3
>>> type(a)
<class 'float'>

    数字
包括整数、浮点数。


删除数字对象引用,例如:
a=1;
b=2;
c=3;
del a;
del b, c;
#print a; #删除a变量后,再调用a变量会报错

>>> a = 1;
>>> b = 2;
>>> c = 3;
>>> del a;
>>> del b,c;
>>> print (a)
Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    print (a)
NameError: name 'a' is not defined

还有数组,函数,日期时间等数据类型。。。



pycharm开发工具:

    一种python的ide集成开发环境,具备的功能,比如, 调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、单元测试、版本控制。方便用户进行Debug,审阅和编写代码。

    pycharm运行的前提是需要先安装python官方的软件,它在运行时也是调用python进行的。


    下载地址:https://www.jetbrains.com/pycharm/download/download-thanks.html?platform=windows

 激活:server选项里边输入 http://idea.imsxm.com/





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章