zoukankan      html  css  js  c++  java
  • Python编程 从入门到实践-2变量上

     笔记出处(学习UP主视频记录) https://www.bilibili.com/video/av35698354?p=2

    2.2 变量

    message = "Hello Python world!"
    print (message)
    message = "Hello Pyhton Crash Course world!"
    print (message)

    Hello Python world!
    Hello Pyhton Crash Course world!

    2.2.2 使用变量时避免命名错误

    message = "Hello Python Crash Course reader!"
    print (mesage)

    print (mesage)
    NameError: name 'mesage' is not defined

    2.3 字符串

    print ("This is a string.")
    print ('This is also a string.')

    This is a string.
    This is also a string.

    2.3.1 使用方法修改字符串的大小写

    name = "ada lovalace"
    print (name.title())

    Ada Lovalace

    name = "ada Lovalace"
    print (name.upper())

    ADA LOVALACE

    name = "ada Lovalace"
    print (name.lower())

    ada lovalace

    2.3.2 合并(拼接)字符串

    first_name = "ada"
    last_name = "lovelace"
    full_name = first_name + " " + last_name
    
    print (full_name)

    ada lovelace

    first_name = "ada"
    last_name = "lovelace"
    full_name = first_name + " " + last_name
    
    print ("Hello, " + full_name.title() + "!")

    Hello, Ada Lovelace!

    first_name = "ada"
    last_name = "lovelace"
    full_name = first_name + " " + last_name
    
    message = "Hello, " + full_name.title() + "!"
    print (message)

    Hello, Ada Lovelace!

    2.3.3 使用制表符或换行符来添加空白

    print ("	Python")
    print ("Python")

        Python
    Python

    print ("Language:
    Python
    C
    JavaScript")

    Language:
    Python
    C
    JavaScript

    print ("Languages:
    	Python
    	C
    	JaveScript")

    Languages:
        Python
        C
        JaveScript

  • 相关阅读:
    hashlib模块
    sys模块
    random模块
    time模块
    生成器、迭代器
    装饰器
    函数相关内容
    集合相关操作
    springcloud(四):Eureka的配置详解
    springcloud(二):Eureka服务注册与发现
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/12467411.html
Copyright © 2011-2022 走看看