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

  • 相关阅读:
    SQLSERVER2000使用TSQL将数据导入ACCESS并压缩生成rar
    收回动态VHD的未使用空间
    如何在html中添加引用公共模块文件 bling
    C语言I博客作业02
    C语言I博客作业06
    C语言I博客作业05
    C语言I博客作业04
    C语言I博客作业03
    Kali 安装JAVA(来源:oschina)
    DHCP服务器内网攻击测试
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/12467411.html
Copyright © 2011-2022 走看看