본문 바로가기
Study Note/Python

1. Variable declaration and data types

by jhleeatl 2024. 3. 25.

 

When learning Python, the most important thing is not to memorize all the code and concepts, but to improve the ability to become familiar with and utilize them in order to make the desired results.

 

 

Here's an example regarding the most basic aspect of Python, which is inputting values:

 

a = 3        
print(a)
b = a       
print(b)
a = 5   
print(a, b)  # 5 3

 

# input value
name = "jun "
age = "18"

# print the value
print("Hello Mr", "name")
print("You are", age, "old.")

 

 

 

 

String & Numeric data

 

Numeric values and strings are different. When you add a (') to a value, it becomes a string. Adding two strings together concatenates them, while in the case of numeric values, they are calculated. However, an error occurs when you try to add a string to a numeric value.

 

a = '2'
b = 'hello'

print(a+b)

 

Result

 

a = 2
b = 'hello'

print(a+b)

Result

 

 

Len(ght)

text = 'abcdefg'
result = len(text)
print (result)

 

 

[:3]

text = 'abcdefg'
result = text[:3]
print (result)

 

Result : abc

 

 

 

[3:]

text = 'abcdefg'
result = text[3:]
print (result)

 

Result : defg

 

 

[3:5]

text = 'abcdefg'
result = text[3:5]
print (result)

 

Result : de

 

 

Split

myemail = 'abc@gmail.co'
result = myemail.split('@')[1].split('.')[0]
print(result)

 

Result : gamil

 

 

 

'Study Note > Python' 카테고리의 다른 글

6. Set & tuples and list  (0) 2024.03.27
5. Uses of [] {} ()  (0) 2024.03.26
4. Function [Def]  (0) 2024.03.26
3. IF & loop  (0) 2024.03.25
2. List & dictionary  (0) 2024.03.25