标签:color 也会 声明 声明变量 习惯 用户 java license edit
1.变量变量是用于存储数据
name = "vita"
pep8规范:等号两边要有空格
驼峰体
AgeOfVita = 27
下划线
age_of_vita = 27
变量名为中文、拼音 名字 = "vita"
变量名过长 qeqweqwe_qweqweqw_qwewqeq
变量名词不达意 a = 23
常量即指不变的量,如pai 3.1415926 ,或在程序运行过程中不会改变的量。
Python中没有专门的语法定义常量,程序员约定用变量名全部大写代表常量。
python中可自定义一个不修改的常量的类。
AGE_OF_VITA = 27
Java中定义常量,修改该常量会报错
public static final String SUNDAY = "SUNDAY";
c语言中定义常量,修改该常量也会报错
const int count = 60;
在使用中变量和常量没什么区别
Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> a = 1
>>> b = a
>>> print(a)
1
>>> print(b)
1
>>> a=2
>>> print(a)
2
>>> print(b)
1
>>>
>>>
>>> A = 10
>>> B=A
>>> print(A)
10
>>> print(B)
10
>>> A=20
>>> print(A)
20
>>> print(B)
10
>>>
name = input("please input your name:")
age = input("please input your age:")
hometown = input("please input your hometown:")
print("your name is:"+name
+ " your age is:"+age
+ " your hometown is:"+hometown)
运行
E:\PythonProject\python-test\venvP3\Scripts\python.exe E:/PythonProject/python-test/BasicGrammer/test.py
please input your name:vita
please input your age:27
please input your hometown:jl
your name is:vita your age is:27 your hometown is:jl
本行注释
age = input("please input your age:") # age pep8规范:#号前面至少两个空格,后面一个空格
单行注释
hometown = input("please input your hometown:")
# print age pep8规范:#号前面无空格,后面一个空格
多行注释
"""
print age
name hometown
"""
‘‘‘
print age
name hometown
pep8规范:注释与下面的代码的空行不能多于两行
‘‘‘
print("your name is:"+name
+ " your age is:"+age
+ " your hometown is:"+hometown)
标签:color 也会 声明 声明变量 习惯 用户 java license edit
原文地址:https://blog.51cto.com/10983441/2380515