Download & Install

리눅스에 Python3 설치하기

GGkeeper 2021. 11. 6. 23:49

실습> 리눅스에서 파이썬 설치하기

https://www.python.org/


[root@localhost ~]# python
Python 2.7.5 (default, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()

[root@localhost ~]# yum -y install python3


[root@localhost ~]# python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

python 소스설치
https://cafe.naver.com/linuxmasternet/1120

python3 사용

print() 함수 : 화면에 출력하는 함수
print("Hello python!")  "Hello python!" 을 화면에 출력한다.
print('Hello python!')  'Hello python!' 을 화면에 출력한다.

변수 : 데이터를 저장할 때 사용하는 저장 공간이다. (RAM 에 존재한다.)
문자열 : 문자가 2개 이상 모여있으면 문자열이 된다.
변수명 = "문자열"

message = 'Hello python!'
print(message)
>>> print(message)
Hello python!
>>> quit()

파이썬을 파일로 작성해서 실행시키는 방법


1. 파일을 생성한 후 python 명령어로 실행하는 방법
[root@localhost ~]# vi test1.py

print('Hello python!')
print('미래에는 멋진 정보보안 전문가를 꿈꾸며!!!')


[root@localhost ~]# python3 test1.py
Hello python!
미래에는 멋진 정보보안 전문가를 꿈꾸며!!!

2. 파일을 생성한 후 실행권한을 주고 실행하는 방법
[root@localhost ~]# which python3
/usr/bin/python3

[root@localhost ~]# vi test2.py

#!/usr/bin/python3
print('Hello python!')
print('WhiteHat 을 꿈꾸며!!! ^^*')


[root@localhost ~]# chmod 755 test2.py
[root@localhost ~]# ls -l test2.py
-rwxr-xr-x. 1 root root 81 11월  1 16:53 test2.py

[root@localhost ~]# ./test2.py
Hello python!
WhiteHat 을 꿈꾸며!!! ^^*