Language

# 함수 정의def add(a, b): result = a + b return result# 함수 호출sum = add(3, 5)print("합계:", sum) # 출력: 합계: 8
text = 'abcd'text.isalpha() >>> True
1. 키워드 사용 불가2. 숫자로 시작 할 수 없다3. 공백을 포함 할 수 없다.4. 특수문자 _만 허용
Error :SyntaxError: Non-ASCII character '\xed' in file t.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details코드 상단에 아래와 같이 작성문자 인코딩이 utf-8# -*- coding: utf-8 -*-문자 인코딩이 euc-kr# -*- coding: euc-kr -*-예시# -*- coding: utf-8 -*-import json# JSON 파일 경로file_path = "data_test.json"
import datetimecurrent_time = datetime.datetime.now()print("Current time:", current_time)
# 두 수를 더하는 간단한 람다 함수add = lambda x, y: x + yprint(add(5, 3)) # 출력: 8# 리스트의 각 요소에 2를 곱하는 람다 함수를 map 함수와 함께 사용하는 예제numbers = [1, 2, 3, 4, 5]doubled_numbers = list(map(lambda x: x * 2, numbers))print(doubled_numbers) # 출력: [2, 4, 6, 8, 10]# 람다 함수를 정렬 기준으로 사용하는 예제points = [(1, 2), (3, 1), (5, 3), (4, 0)]points.sort(key=lambda x: x[1]) # 두 번째 요소를 기준으로 정렬print(points) # 출력: [(4, 0), (3, 1), (1, 2)..
def snake_to_camel(snake_case): components = snake_case.split('_') camel_case = components[0] + ''.join(x.title() for x in components[1:]) return camel_case# 사용 예시snake_case = "my_variable_name"camel_case = snake_to_camel(snake_case)print(camel_case) # result : myVariableName
# 입력한 숫자가 양수인지 음수인지를 판별하는 예제num = int(input("숫자를 입력하세요: "))if num > 0: print("입력한 숫자는 양수입니다.")elif num
# 1부터 5까지의 숫자를 출력하는 예제num = 1while num
# 리스트의 각 요소에 대해 반복하여 출력하는 예제fruits = ["사과", "바나나", "딸기"]for fruit in fruits: print(fruit)
def to_snake_case(text): result = ''.join(['_' + c.lower() if c.isupper() else c for c in text]).lstrip('_') return resultoriginal_text = "getTimeStamp"snake_case_text = to_snake_case(original_text)print(snake_case_text) # result : get_time_stamp
자료형숫자형 (int, float, complex)문자열 (str)리스트 (list)튜플 (tuple)집합 (set)사전 (dictionary)숫자형# 두 숫자를 더한 결과 출력num1 = 10num2 = 20result = num1 + num2print("두 숫자의 합:", result)문자열# 문자열 합치기str1 = "Hello"str2 = "World"result = str1 + " " + str2print(result)리스트# 리스트 순회하며 합계 계산numbers = [1, 2, 3, 4, 5]total = 0for num in numbers: total += numprint("리스트의 합계:", total)튜플# 튜플 순회하며 값 출력tup = (1, 2, 3, 4, 5)for valu..
try: # 예외가 발생할 수 있는 코드 result = 10 / 0 # 예외를 발생시킵니다.except Exception as e: # 모든 예외를 처리하는 예외 처리 print("예외가 발생했습니다:", e)
import json # 주어진 리스트 data = [ {"name": "콜라", "price": 26}, {"name": "김밥", "price": 27}, {"name": "사이다", "price": 28} ] # 각 객체를 JSON 문자열로 변환하고 합치기 json_string = '{' + ', '.join(json.dumps(obj, ensure_ascii=False) for obj in data) + "}" # 결과 출력 print(json_string) #결과 {{"name": "콜라", "price": 26}, {"name": "김밥", "price": 27}, {"name": "사이다", "price": 28}}
숫자 구분 기호 (Numeric Separators)를 이용하여 숫자 가독성 표시를 할 수 있음 let price = 10_000_000; console.log(price); //결과 : 10000000
문법 : ?. 설명 : ?. 앞에 선언된 필드가 undefined, null이면 undefined 반환, 값이 true 이면 세팅값을 반환 const person = { job: { manager: { name: 'hongkildong', }, }, }; //정의되지 않은 키(manager2) 참조 시 에러 없이 undefined 반환 console.log(person.job && person.job.manager2 && person.job.manager.name); // undefined //정의되지 않은 키(manager2) 참조 시 에러 발생 console.log(person.job.manager2.name); // Error VM557:1 Uncaught TypeError: Cannot read ..
function getfileSize(x) { var s = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']; var e = Math.floor(Math.log(x) / Math.log(1024)); return (x / Math.pow(1024, e)).toFixed(2) + " " + s[e]; };
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class FileZipCreate { //zip파일 생성 메서드 public static void zipDirectory(String dir, String zipfile) throws IOException, IllegalArgumentException { //디렉토리 존재 유무 체크 및 해당 파일 리스트를 가져오기 위하여 객체 생성 File d = new File(di..
import java.text.DecimalFormat; public class Price1000Comma { public static void main(String[] args) { DecimalFormat df = new DecimalFormat("#,###.######"); double amtDouble = 1234567890.123456; String amtString = df.format(amtDouble); System.out.println(amtString); } }
기능 1. 대용량 데이터를 엑셀로 내려 받음. 2. 셀 머지 기능 3. 시트별로 데이터를 출력 ※ xml를 사용한 방법 ※ xml를 사용하지 않고 RowHandler만 사용한 방법 ( 이경우는 데이터가 많은경우 Out Of Memory가 발생 하였음) 첨부파일에 컨트롤러 파일을 참고 설명 일반적으로 엑셀로 대용량 데이터를 내려 받을경우 Out Of Memory 가 발생하게 된다. 그래서 Heap Size를 늘려주기도 하고 데이터를 나눠서 엑셀로 내려받는 등 여러가지 방법으로 구현하기도 한다. 이러한 문제점들을 해결할수 있게 XML 형식으로 대용량 처리하여 엑셀로 내려 받을수 있게 되는데 스프링, iBatis(myBatis), poi등을 이용하여 구현하게 된다. 일반적으로 엑셀 내려받기 위하여 10만건을 ..
import java.text.DecimalFormat; public class ByteCal { public String byteCalculation(String bytes) { String retFormat = "0"; Double size = Double.parseDouble(bytes); String[] s = { "bytes", "KB", "MB", "GB", "TB", "PB" }; if (bytes != "0") { int idx = (int) Math.floor(Math.log(size) / Math.log(1024)); DecimalFormat df = new DecimalFormat("#,###.##"); double ret = ((size / Math.pow(1024, Math.flo..
방법1 public class NumberCheck { public static void main(String[] args) { System.out.println("## 숫자 체크 정수, 실수 : " + isStringDouble("1500")); System.out.println("## 숫자 체크 정수, 실수 : " + isStringDouble("1500.123")); System.out.println("## 숫자 체크 정수, 실수 : " + isStringDouble("1500T")); } public static boolean isStringDouble(String s) { try { Double.parseDouble(s); return true; } catch (NumberFormatExcept..
import java.security.SecureRandom; public class RandomTest { public static void main(String[] args) { /* * Math.random()은 취약하다는 보안검사를 통해서 이야기를 들은적이 있다. * 따라서 new SecureRandom()를 쓰기를 권장한다. */ System.out.println("Math.random() : "+Math.random()); System.out.println("SecureRandom() : "+new SecureRandom().nextDouble()); } }
window.open("about:blank").location.href = "http://www.test.com";
public class CipherTest { public static void main(String[] args) throws Exception { //String encryptKey = "암호화키"; //22db8b13823131fa58928507ad7add61 : 암호화키 //String iv = "IV키"; //02130995e8a1bfbffd39df4e3bd5b344 : IV키 String txt = "여기에 암호화할 문자를 입력해주세요."; String enc = new String(CipherUtil.AES_Encode(txt , "22db8b13823131fa58928507ad7add61", "02130995e8a1bfbffd39df4e3bd5b344")); String str = new ..
· Language/Jsp
package jsp.util; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Cookie; import java.util.Map; import java.net.URLEncoder; import java.net.URLDecoder; import java.io.IOException; public class CookieBox { private Map cookieMap = new java.util.HashMap();//쿠키를 쌍으로 저장하는 맵 public CookieBox(HttpServletRequest request) { //생성자, 인자로 request를 받는다 Cookie[] cookies = request.getCoo..
· Language/Jsp
100 : Continue 101 : Switching protocols 200 : OK, 에러없이 전송 성공 201 : Created, POST 명령 실행 및 성공 202 : Accepted, 서버가 클라이언트 명령을 받음 203 : Non-authoritative information, 서버가 클라이언트 요구 중 일부 만 전송 204 : No content, 클라언트 요구을 처리했으나 전송할 데이터가 없음 205 : Reset content 206 : Partial content 300 : Multiple choices, 최근에 옮겨진 데이터를 요청 301 : Moved permanently, 요구한 데이터를 변경된 임시 URL에서 찾았음 302 : Moved temporarily, 요구한 데이터가 ..
728x90
반응형
공손(gongson)
'Language' 카테고리의 글 목록