Learn about python's print function and strings for beginners.

Note: This article starts with a python environment in place

Introduction

Nice to meet you, in this article I would like to write the first thing I learned in python.

First of all, hello world

I think this is the first thing a beginner will learn when learning python. Anyway, write the following code in the interactive code and press enter.

hello.py


print("hello world")

Try running it. Then it should come out like this.

hello.py


hello world

It just used the print function to print the characters in the double quotes as a string. A character string is a series of characters. Even one character can be read as a character string. However, the character string cannot be calculated because it is different from the number due to characters. The command is simply a command to display hello world.

Let's use numbers

Mr. a wants to calculate 1 + 1, but I don't know. I decided to calculate using python. But I'm in trouble because I can't get an answer. The code of Mr. a is as follows.

asan.py


print("1 + 1")

Execution result

asan.py


1 + 1

As you may have noticed, this will display it as a string. So to go back from a string to a number, write:

asannotameni.py


print(1 + 1)

Execution result

asannotameni.py


2

Now you have a 1 + 1 answer. In this way, python has to use strings and numbers properly.

Summary

This time, I wrote a little about the print function. Next time I will write in more detail. Please read it again next time.

bonus

Mr. a submitted a 1 + 1 question to the school, but he made a mistake and submitted it as 1 + 1. And he said he tried again, laughing at everyone alone.

Recommended Posts

Learn about python's print function and strings for beginners.
About python beginner's memorandum function
About fork () function and execve () function
Python #function 2 for super beginners
How to learn TensorFlow for liberal arts and Python beginners
Python #len function for super beginners
Don't print and import logging for logging
Learn about logging using Python's logging module ①
Don't learn Java and C ++! !! Languages for beginners [more carefully selected]
About _ and __
Causal reasoning and causal search with Python (for beginners)
[Python] Learn about asynchronous programming and event loops
About Python external module import <For super beginners>